|
|
Wasn't it LightBeam who wrote:
>Hello, here is my problem:
>I started with a spline to create a kind of link but I have no idea how
>to make the cylinders follow 'nicely' the curve.. What is the solution
>to make them aligned and rotated to fit the spline/curve ? (Joined the
>source) Please help me...
I'd do it by using Reorient_Trans to rotate the cylinders. The cylinders
are currently pointing in the z direction and we want them aligned along
the spline, so we reorient them like this
#include "transforms.inc"
cylinder {<0.0, 0.0, -0.02><0.0, 0.0, 0.02>0.07
transform {Reorient_Trans(z,Direction)}
An alternative method would be to create the cylinder already oriented
in the required direction. This works with simple shapes like cylinders
but with a complex shape use Reorient_Trans.
cylinder {-0.02*vnormalize(Direction),0.02*vnormalize(Direction),0.07
But we need to find the direction of the spline. This can normally be
achieved by taking the difference two locations from the spline, like
this:
#declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));
Unfortunately, this gives a problem if you try to use it on a point
that's off the end of the spline, because it returns the zero direction
and you can't use that in Reorient_Trans. This can either be solved by
treating points that are off the end of the spline as a special case
#declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));
#if (vlength(Direction) = 0)
#declare Direction = x;
#end
or by confining yourself to only using points that are on the spline,
noting this paragraph in the documentation "Note: Because of the way
cubic_splines are defined: the first and last points are tangents rather
than points on the spline, cubic_spline interpolation is only valid
between the second and next-to-last points."
#declare ctr = 0.1;
#declare Spacing = 0.01;
#while (ctr < 0.4)
Here's the whole thing put together using only the valid region of the
cubic_spline
camera {location <0.0, 2.0, -2.0> look_at 0.0}
light_source {<100.0, 300.0, -50.0>1.0}
plane {y, -0.5 pigment {rgb 0.7}}
#declare Spline =
spline {
cubic_spline
0.00, <1,0,0>
0.10, <0,0,1>
0.20, <-1,0,0>
0.30, <0,0,-1>
0.40, <0,0,0>
0.50, <1,0,0>
}
#declare ctr = 0.003;
#declare Spacing = 0.001;
#while (ctr < 0.7)
sphere {0.0, 0.03
translate Spline(ctr)
pigment {rgb 0.3}
}
#declare ctr = ctr + Spacing;
#end
#declare ctr = 0.1;
#declare Spacing = 0.01;
#while (ctr < 0.4)
#declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));
cylinder {-0.02*vnormalize(Direction),0.02*vnormalize(Direction),0.07
translate Spline(ctr)
pigment {rgb 0.3}
}
#declare ctr = ctr + Spacing;
#end
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|
|
|
LightBeam wrote:
>
> #declare ctr = 0.003;
> #declare Spacing = 0.01;
> #while (ctr < 0.7)
> cylinder {<0.0, 0.0, -0.02><0.0, 0.0, 0.02>0.07
> translate Spline(ctr)
> pigment {rgb 0.3}
> }
> #declare ctr = ctr + Spacing;
> #end
>
As a rough and ready answer I sometimes do this:
#local B=0; #while ( B+1 < 50 )
#local Pt = SplineA( B/50 );
#local Pt2 = SplineA( (B+1)/50 );
cylinder { Pt, Pt2, .0055 pigment { rgb < 0, 1, 0 > } }
#local B=B+1;#end
Post a reply to this message
|
|