POV-Ray : Newsgroups : povray.general : Use bezier_spline shape in a sphere_sweep? : Re: Use bezier_spline shape in a sphere_sweep? Server Time
30 Jul 2024 06:19:47 EDT (-0400)
  Re: Use bezier_spline shape in a sphere_sweep?  
From: Chris B
Date: 15 Aug 2009 09:28:24
Message: <4a86b7f8$1@news.povray.org>
"CShake" <cshake+pov### [at] gmailcom> wrote in message 
news:4a85a542@news.povray.org...
> Hello all,
> I'm currently working on a model with a lot of lathe and prism objects, 
> and I'm using bezier_spline for the outlines because it's much easier to 
> get the shape right (and I'm familiar with how they work). My question is 
> that I have a bent strip of plastic (a handle actually) that I have 
> modeled with a prism, only because there is no method for sweeping an oval 
> or other shape along a spline (which would be ideal). With this method, it 
> has sharp edges all along the sides, and I'd like to add a sphere_sweep 
> along both sides to round it out. Is there any way for me to add a 
> sphere_sweep with the same path data (bezier), or would I need to redo the 
> whole thing with a cubic?
>

I don't think there's a simple answer to your question, so I've tried to 
cover quite a few different bases here, hence the somewhat long-winded 
answer.

If I were doing this I'd probably just sweep a shape along a cubic spline. 
The example that I've pasted below illustrates this.
I've used a cylinder and two spheres, but this shape could also be a prism 
or more-or-less any other shape. It's also pretty easy to scale the shape as 
it moves along, either uniformly or just in a single direction, such as the 
'y' direction.

Althernatively Mike Williams has a SweepSpline macro that may provide you 
with a solution. This can be downloaded from the little Yellow panel at the 
bottom of his tutorial page at http://www.econym.demon.co.uk/isotut/more.htm


OTOH to try and answer your actual question: From your description I'm 
imagining that you're starting with a sort of rounded humped profile that is 
then extruded a little bit as a prism, resulting in a flat-edged handle 
object. I'm not sure whether you're asking how to:
  A:  Run a sphere_sweep down the centre line of each flat surface or
  B:  Run a sphere_sweep around each edge, resulting in a sort of recess 
down the middle of the two flat faces.
so I've tried to cover both cases.

The main problem is that, in both cases, you don't actually want the middle 
of the sphere_sweep to follow the same path as the perimeter of the prism 
object.  In the first case you would want to steer a course down the middle 
of the opposite edges of the prism, adjusting the radius of the sphere sweep 
as you go to line up with the two surfaces. In the second case you'd need to 
inset the line of the curve of the sphere_sweep to line up with the outer 
edge of the prism.

It is possible (although not totally straight-forward) to use the trace 
function to do either of these, effectively 'scanning' the surfaces of the 
prism and calculating the points you need. If you 'scan' at small enough 
intervals the type of spline you use in the sphere_sweep can become largely 
irrelevant.

An alternative approach for 'B' would be to create a spline function (no 
support for bezier splines) which you can use for the line of the edge of 
the prism and also for calculating an amount to inset a sphere_sweep that 
follows the edge. This approach doesn't fit so well with the 'down the 
middle' option though.

It's a bit more difficult thinking of an alternative approach for 'A'. You 
could use a succession of thin slice scaled down at the two ends to round 
the edges, but it's likely to be difficult to get it to look right on this 
sort of shape. You could also consider using the conic_sweep capabilities of 
the prism object to create multiple slices of handle that follow your bezier 
splines. This is a little hard to explain without a white-board, but, 
imagine taking a conic prism, that dissappears to an apex at one end of the 
extrusion and using CSG to slice off a layer at the other end. You end up 
with a bevelled slice that you can but onto the end of a prism generated 
using the same bezier curve and a linear_sweep. This is also not ideal in 
this scenario with a long-thin object as the bevel would not be at a uniform 
angle.


Anyway. Back to the solution that I'd probably recommend, which creates a 
cubic spline function and then runs copies of an object along that path to 
create a curved object. Try uncommenting the 'scale' directive to play with 
non-uniform scaling.


camera {location <-0.4, 1,-1> look_at <0.5,0.3,0>}
light_source {<1,10,-1> color rgb 1}

#declare PointCount = 6;
#declare SeparationRatio = 0.01;
#declare Segments = PointCount-1;

#declare MySpline = spline {
  cubic_spline
  -0.25, <-0.5,0   ,0>
   0.0 , < 0  ,0   ,0>
   0.2 , < 0.2,0.18,0>
   0.4 , < 0.4,0.2 ,0>
   0.6 , < 0.6,0.2 ,0>
   0.8 , < 0.8,0.18,0>
   1.0 , < 1  ,0   ,0>
   1.25, < 1.5,0   ,0>
}

#declare SweepThickness = 0.03;
#declare SweepObject = union {
  sphere {<0,0,-0.05>,SweepThickness}
  sphere {<0,0, 0.05>,SweepThickness}
  cylinder {<0,0,-0.05>,<0,0, 0.05>,SweepThickness}
}

// Loop through the spline
#declare Ctr = 0;
#while (Ctr < 1)
  object {SweepObject
    pigment { rgb <1,0,0>}
//    scale <1,max(10*MySpline(Ctr).y,1),1>
    translate MySpline(Ctr)
  }
  #declare Ctr = Ctr + 0.001;
#end

// Axes
cylinder {-10*x,10*x,0.01 pigment {rgb <1,0,1>}}
cylinder {-10*y,10*y,0.01 pigment {rgb <1,1,0>}}
cylinder {-10*z,10*z,0.01 pigment {rgb <0,1,1>}}



Regards,
Chris B.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.