POV-Ray : Newsgroups : povray.advanced-users : struggle with splines : Re: struggle with splines Server Time
6 Oct 2024 13:01:06 EDT (-0400)
  Re: struggle with splines  
From: Warp
Date: 4 Oct 2006 10:07:34
Message: <4523c026@news.povray.org>
Chrisir <nomail@nomail> wrote:
> How can I make positively sure that my spline starts exactly
> always and definetly in P1 and ends exactly
> always and definetly in P2?

>         #declare ctr = 0;

>         #while (ctr < 1)
            ...
>           #declare ctr = ctr + 0.01;
>         #end   // end of while

  Basic programming "trick":

  You shouldn't use such a floating point number directly as your loop
counter. 0.01 cannot be represented accurately in binary floating point
and thus the sum you are accumulating in 'ctr' will become more and more
inaccurate, and there's a high chance that the loop will not be executed
the exact amount of times you want.
  Instead, you should do it like this:

#declare Index = 0;
#while(Index < 100)
  #declare ctr = Index/99;

  ... (the loop body, which uses 'ctr') ...

  #declare Index = Index+1;
#end

  This makes sure that the loop will be executed exactly 10 times and
that 'ctr' will get values between exactly 0 and 1.

-- 
                                                          - Warp


Post a reply to this message

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