POV-Ray : Newsgroups : povray.general : Use bezier_spline shape in a sphere_sweep? Server Time
4 Nov 2024 17:31:47 EST (-0500)
  Use bezier_spline shape in a sphere_sweep? (Message 1 to 4 of 4)  
From: CShake
Subject: Use bezier_spline shape in a sphere_sweep?
Date: 14 Aug 2009 13:56:18
Message: <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?

On a related note, the b_spline in the sphere_sweep section has no 
documentation besides "b_spline : Approximating the input data using a 
cubic b-spline function, which results in a curved object.", Unlike all 
the other types which have examples in the tutorial section with an 
explanation of how each point is used. More than a sentence about it 
might help.


Post a reply to this message

From: Chris B
Subject: Re: Use bezier_spline shape in a sphere_sweep?
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

From: CShake
Subject: Re: Use bezier_spline shape in a sphere_sweep?
Date: 15 Aug 2009 16:12:35
Message: <4a8716b3$1@news.povray.org>
Chris B wrote:
> 
> "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.

Thanks for the very in-depth response!

What I was thinking was more along the lines of option A that you 
suggested, but I will take a look at the SweepSpline macro you pointed 
me to, since it may be the easiest way. If I could use the same spline 
in sphere_sweep as I did in the prism contour (with the addition of a 
z-coordinate and radius of course), I'd be able to define the respective 
'z' of each sweep as the top and bottom of the previously defined prism.

To illustrate the problem better, I'm trying to model the handle on a 
handbell, you can see it here: 
http://commons.wikimedia.org/wiki/File:Hand_bell3.jpg

To describe more, lets say that the circular disc at the base of the 
handle is the x-z plane, the handle extends in y, and the writing ('F3' 
here) is more or less on the y-z plane. If you define the joint of the 
handle and disc as the origin, the camera in that picture would then be 
in the general <+,0,-> direction and rotated 100 degrees clockwise.

The white plastic part of the handle is what I modeled with the prism 
object, with the points in x-y and extruded +-z. What I'd really like to 
do is define the contour of the clear plastic (basically a rectangle 
with rounded corners) in the x-z and sweep it along a curve in x-y.

You can see that the prism with hard edges does a decent approximation 
of the shape, but in the actual object the sides are slightly larger 
than the middle of the plastic strip and they're rounded.

And here is what I've actually done so far, so you can see: 
http://cshake.deviantart.com/art/CGI-Handbell-MK1-133360701

Maybe I should have posted this in p.a-u come to think of it...

CShake


Post a reply to this message

From: Chris B
Subject: Re: Use bezier_spline shape in a sphere_sweep?
Date: 16 Aug 2009 12:48:33
Message: <4a883861@news.povray.org>
"CShake" <cshake+pov### [at] gmailcom> wrote in message 
news:4a8716b3$1@news.povray.org...
>
> Thanks for the very in-depth response!
>
> What I was thinking was more along the lines of option A that you 
> suggested, but I will take a look at the SweepSpline macro you pointed me 
> to, since it may be the easiest way. If I could use the same spline in 
> sphere_sweep as I did in the prism contour (with the addition of a 
> z-coordinate and radius of course), I'd be able to define the respective 
> 'z' of each sweep as the top and bottom of the previously defined prism.
>
> To illustrate the problem better, I'm trying to model the handle on a 
> handbell, you can see it here: 
> http://commons.wikimedia.org/wiki/File:Hand_bell3.jpg
>

Ahh! Now this moves the goal posts a little for two reasons.

Because this is a flexible fabric bell handle that folds back on itself, it 
makes it very difficult to use the trace function to 'scan' the surface of 
your existing prism object, so I'd say that option is out. Because the 
handle incorporates an outer transparent sleeve it would make the #while 
loop approach extremely inefficient, because POV_Ray would have to do one 
heck of a lot of ray tests. I did a quick test using that technique and it 
took over an hour on 3.6. For some reason the same scene in 3.7 caused 
POV-Ray to run out of memory after a few minutes (and my machine's got quite 
a bit of memory).

I think that Mike's macro is likely to offer the approach of least pain, but 
I suspect you'll need to redo the spline as a cubic_spline.

Regards,
Chris B.


Post a reply to this message

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