POV-Ray : Newsgroups : povray.advanced-users : Animating lengthening splines Server Time
1 Nov 2024 13:19:38 EDT (-0400)
  Animating lengthening splines (Message 1 to 4 of 4)  
From: scott
Subject: Animating lengthening splines
Date: 16 Jun 2005 11:30:35
Message: <42b19b1b$1@news.povray.org>
OK, this is what I want to do:

I want to define a spline (or set of points), then be able to say "draw 43%
of this spline" or whatever.  It would then draw the first 43% of this
spline, and not the rest.  I'm going to use this in an animation to show a
spline gradually getting longer at constant speed.

Now, this is a bit trickier than it sounds, because the spline will not be
equal lengths between each point, and because i'll be using cubic or
something, the spacing between the points will not be linear.

I tried to make a macro that stepped through the spline and measured the
length to work out where the "cut-off" point was, but to make it accurate
enough I had to use a really small step size, and it took forever to parse.

Anyone have any clever ideas? Or better yet, some code, or some weird
built-in function I'm missing?


Post a reply to this message

From: Chris B
Subject: Re: Animating lengthening splines
Date: 16 Jun 2005 12:22:23
Message: <42b1a73f$1@news.povray.org>
"scott" <sco### [at] spamcom> wrote in message news:42b19b1b$1@news.povray.org...
> OK, this is what I want to do:
>
> I want to define a spline (or set of points), then be able to say "draw
43%
> of this spline" or whatever.  It would then draw the first 43% of this
> spline, and not the rest.  I'm going to use this in an animation to show a
> spline gradually getting longer at constant speed.
>
> Now, this is a bit trickier than it sounds, because the spline will not be
> equal lengths between each point, and because i'll be using cubic or
> something, the spacing between the points will not be linear.
>
> I tried to make a macro that stepped through the spline and measured the
> length to work out where the "cut-off" point was, but to make it accurate
> enough I had to use a really small step size, and it took forever to
parse.
>
> Anyone have any clever ideas? Or better yet, some code, or some weird
> built-in function I'm missing?
>
>

Well I think this is a clever idea, but I'm willing to stand corrected if it
turns out to be a dumb one :-)
Isn't what you want virtually what the example in the POV-Ray help does
with:

camera { location <0,2,-2> look_at 0 }
light_source { <-5,30,-10> 1 }
#declare MySpline =
  spline {
    cubic_spline
    -.25, <0,0,-1>
    0.00, <1,0,0>
    0.25, <0,0,1>
    0.50, <-1,0,0>
    0.75, <0,0,-1>
    1.00, <1,0,0>
    1.25, <0,0,1>
  }

#declare ctr = 0;
#while (ctr < 1)
  sphere {
    MySpline(ctr),.25
    pigment { rgb <1-ctr,ctr,0> }
  }
  #declare ctr = ctr + 0.01;
#end
The points themselves wouldn't have to be uniformly spaced, but you would
need to be able to identify the lengths of each segment and set the values
given when defining the spline to be proportional to those lengths, then you
could use #while (ctr < 0.43) to give you a spline that's 43% of the total
length.You'd need to adjust the increment to give you smooth looking line. I
tried the above with 0.001 instead of 0.01 and it looked pretty smooth to
me.Regards,Chris.


Post a reply to this message

From: Chris B
Subject: Re: Animating lengthening splines
Date: 16 Jun 2005 13:49:32
Message: <42b1bbac$1@news.povray.org>
Here's an adaptation that measures the length of the spline first:

camera { location <0,2,-2> look_at 0 }
light_source { <-5,30,-10> 1 }
#declare MySpline =
  spline {
    cubic_spline
    -.25, <0,0,-1>
    0.00, <1,0,0>
    0.25, <0,0,1>
    0.50, <-1,0,0>
    0.75, <0,0,-1>
    1.00, <1,0,0>
    1.25, <0,0,1>
  }


#declare Percentage = 43;

#local ctr = 0;
#local SplineLength = 0;
#local OldPoint = MySpline(0);
#while (ctr <= 1)
  #local SplineLength = SplineLength + vlength(MySpline(ctr)-OldPoint);
  #local OldPoint = MySpline(ctr);
  #local ctr = ctr + 0.0001;
#end


#local ctr = 0;
#local DistanceTraveled = 0;
#local OldPoint = MySpline(0);
#while (DistanceTraveled < Percentage*SplineLength/100)
  #local DistanceTraveled = DistanceTraveled +
vlength(MySpline(ctr)-OldPoint);
  #local OldPoint = MySpline(ctr);
  sphere {
    MySpline(ctr),.1
    pigment { rgb <1-ctr,ctr,0> }
  }
  #local ctr = ctr + 0.001;
#end




Chris B.


Post a reply to this message

From: scott
Subject: Re: Animating lengthening splines
Date: 16 Jun 2005 16:07:05
Message: <42b1dbe9@news.povray.org>
"Chris B" <c_b### [at] btconnectcom> wrote in message
news:42b1bbac$1@news.povray.org
> Here's an adaptation that measures the length of the spline first:
>
> camera { location <0,2,-2> look_at 0 }
> light_source { <-5,30,-10> 1 }
> #declare MySpline =
>  spline {
>    cubic_spline
>    -.25, <0,0,-1>
>    0.00, <1,0,0>
>    0.25, <0,0,1>
>    0.50, <-1,0,0>
>    0.75, <0,0,-1>
>    1.00, <1,0,0>
>    1.25, <0,0,1>
>  }
>
>
> #declare Percentage = 43;
>
> #local ctr = 0;
> #local SplineLength = 0;
> #local OldPoint = MySpline(0);
> #while (ctr <= 1)
>  #local SplineLength = SplineLength +
>  vlength(MySpline(ctr)-OldPoint); #local OldPoint = MySpline(ctr);
>  #local ctr = ctr + 0.0001;
> #end
>
>
> #local ctr = 0;
> #local DistanceTraveled = 0;
> #local OldPoint = MySpline(0);
> #while (DistanceTraveled < Percentage*SplineLength/100)
>  #local DistanceTraveled = DistanceTraveled +
> vlength(MySpline(ctr)-OldPoint);
>  #local OldPoint = MySpline(ctr);
>  sphere {
>    MySpline(ctr),.1
>    pigment { rgb <1-ctr,ctr,0> }
>  }
>  #local ctr = ctr + 0.001;
> #end

Thanks for that.  I have done what you said, but also added a bit in the 
second loop so that it only places a sphere every certain distance.  That 
makes the spheres uniformly spaced (more or less) and saves having 
258725892758 spheres to get the long bits smooth!


Post a reply to this message

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