|
![](/i/fill.gif) |
Wasn't it Chrisir who wrote:
>
>
>Hello!
>
>I am looking for a function that helps me with splines.
>
>I want to give the function the ***exact*** start point (x1,y1,z1) and end
>point (x2,y2,z2) of an spline and the height (h) of it - nothing more.
>
>
>All other things should be figured out by the function.
>The spline stands in a right angle to plane below.
>
>
>The stuff in the function should be something similar to what you see below
>the message.
>A sphere i moved along the spline.
>
>The Problem is to get the points ***exactly*** to a given start and end
>position (x,y,z). I'd line to begin the first sphere exact at (above) the
>star-point xyz.
>
>I really like to have a functon doing it.
>
>Thanks a lot!
>
>Chrisir
I'm not sure if it's possible to do it with one function, but here's a
way to do it with three functions. The MakeFun macro creates the three
functions Fx(), Fy() and Fz().
// Fh defines the overall shape of the curve
// Choose a function that is:
// zero when ctr=0
// zero when ctr=0
// one when ctr = 0.5
// here are two possibilites - comment out the one you don't want
#declare Fh = function(a){sin(a*pi)}
//#declare Fh = function(t){4*(t-t*t)}
// Define the macro that creates the functions
#macro MakeFun(P1,P2,Height)
// extract the coordinates of the points
// because you can't use vectors in function declarations
#local P1x= P1.x;
#local P2x= P2.x;
#local P1y= P1.y;
#local P2y= P2.y;
#local P1z= P1.z;
#local P2z= P2.z;
// Undefine the functions, in case we want to call the
// macro more than once
// (redeclaring functions is illegal)
#undef Fx
#undef Fy
#undef Fz
// declare the functions
#declare Fx = function(a){P1x+(P2x-P1x)*a}
#declare Fy = function(a){P1y+(P2y-P1y)*a + Fh(a)*Height}
#declare Fz = function(a){P1z+(P2z-P1z)*a}
#end
// Invoke the macro to create the functions
MakeFun(<-.87,1.05,-.85>, <.64, 1.1,.6>, 1.5)
#declare ctr = 0;
#while (ctr < 1)
sphere {
<Fx(ctr),Fy(ctr),Fz(ctr)>, .05
pigment { rgb <0.5,1,0> }
}
#declare ctr = ctr + 0.01;
#end
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
![](/i/fill.gif) |