POV-Ray : Newsgroups : povray.general : Subdividing a spline Server Time
28 Nov 2024 22:39:28 EST (-0500)
  Subdividing a spline (Message 1 to 7 of 7)  
From: Skip Talbot
Subject: Subdividing a spline
Date: 14 Jul 2006 09:35:42
Message: <44b79dae$1@news.povray.org>
Is there a way to accurately, or quickly and fairly accurately, 
subdivide a spline into equal lengths?  I've written a macro that takes 
small steps along the spline and sums up the distance between the steps. 
   I then divide this length by the number of segments I want, and 
traverse the spline again until this divided distance is reached.  The 
lengths always fall short (as well they should as I lose the curvature). 
The smaller the step the better the accuracy but the parse times start 
getting fairly high.  Less obvious though is that the error increases as 
I increase the number of divisions.  It almost seems like its skipping 
the last step and distance sum for the segment, and thus they the error 
adds up with more segments.

Does anyone have a better approach to this problem or should I scour my 
macro for bugs?

Skip


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Subdividing a spline
Date: 14 Jul 2006 15:52:30
Message: <44b7f5fe$1@news.povray.org>
Skip Talbot wrote:
> Is there a way to accurately, or quickly and fairly accurately, 
> subdivide a spline into equal lengths?  I've written a macro that takes 
> small steps along the spline and sums up the distance between the steps. 
>   I then divide this length by the number of segments I want, and 
> traverse the spline again until this divided distance is reached.  The 
> lengths always fall short (as well they should as I lose the curvature). 
> The smaller the step the better the accuracy but the parse times start 
> getting fairly high.  Less obvious though is that the error increases as 
> I increase the number of divisions.  It almost seems like its skipping 
> the last step and distance sum for the segment, and thus they the error 
> adds up with more segments.
> 
> Does anyone have a better approach to this problem or should I scour my 
> macro for bugs?

You could google for numerical methods to approximate line integrals.

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: Jim Charter
Subject: Re: Subdividing a spline
Date: 15 Jul 2006 06:07:19
Message: <44b8be57$1@news.povray.org>
Skip Talbot wrote:
> Is there a way to accurately, or quickly and fairly accurately, 
> subdivide a spline into equal lengths?  I've written a macro that takes 
> small steps along the spline and sums up the distance between the steps. 
>   I then divide this length by the number of segments I want, and 
> traverse the spline again until this divided distance is reached.  The 
> lengths always fall short (as well they should as I lose the curvature). 
> The smaller the step the better the accuracy but the parse times start 
> getting fairly high.  Less obvious though is that the error increases as 
> I increase the number of divisions.  It almost seems like its skipping 
> the last step and distance sum for the segment, and thus they the error 
> adds up with more segments.
> 
> Does anyone have a better approach to this problem or should I scour my 
> macro for bugs?
> 
> Skip
Sounds like first of all you need to define the spline so that equal 
deltas of the clock value will produce equal intervals along the spline

I use a fairly crude macro for this which suits natural splines

#macro SmoothSpline( Spline, Grain )
//regularizes the spline definition so
//the distance along the spline will be
//more proportional to the clock value
         #local TL=0;
         #local Ptr=1;#while(Ptr<=Grain)
                 #local TL=
                         TL+vlength( Spline(Ptr/Grain)
                         -Spline((Ptr-1)/Grain) );
         #local Ptr=Ptr+1;#end


         #local L=0;

         spline { 

                 natural_spline
                 0 Spline(0)
                 #local Ptr=1;#while(Ptr<=Grain)
                         #local L=
                                 L+vlength( Spline(Ptr/Grain)
                                 -Spline((Ptr-1)/Grain) );

                                 L/TL Spline(Ptr/Grain)
                 #local Ptr=Ptr+1;#end
         }

#end

Then you can divide the spline into equal lengths using equal clock 
deltas.


Post a reply to this message

From: Tim Attwood
Subject: Re: Subdividing a spline
Date: 22 Jul 2006 00:12:39
Message: <44c1a5b7$1@news.povray.org>
"Jim Charter" <jrc### [at] msncom> wrote in message 
news:44b8be57$1@news.povray.org...
> Skip Talbot wrote:
>> Is there a way to accurately, or quickly and fairly accurately, subdivide 
>> a spline into equal lengths?  I've written a macro ...
This seems to work OK.

#include "strings.inc"

#macro Split_Spline(SplA SplB begin_at stop_at rez stype)
   #local Split = concat("#declare ",SplB," = spline {\n",stype,"\n");
   #local c = -rez;
   #while (c <= 1+rez)
      #declare Split = concat(Split,str(c,1,3),",<",
       vstr(3, ABC_spl(c * (stop_at - begin_at) + begin_at),
       ",", 0,3),">\n");
      #local c = c + rez;
   #end
   #declare Split = concat(Split,"};\n");
   Parse_String(Split)
#end

#declare ABC_spl = spline {
    natural_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>
};

Split_Spline(ABC_spl, "AB_spl", 0, 0.5, 0.25, "natural_spline")
Split_Spline(ABC_spl, "BC_spl", 0.5, 1.0, 0.25, "natural_spline")


Post a reply to this message

From: Tim Attwood
Subject: Re: Subdividing a spline
Date: 23 Jul 2006 12:25:23
Message: <44c3a2f3$1@news.povray.org>
The length of a spline equals the sum of the straight sub-lengths as the
interval of evaluation approaches zero.

It also equals the integral of the equation of the spline, or the sum of the
integrals of the definable equations of the segments of the spline.

In other words, if you can figure out the equations involved you could
chop the spline up into fewer pieces and come up with an exact answer in
less time.


Post a reply to this message

From: Tim Attwood
Subject: Re: Subdividing a spline
Date: 23 Jul 2006 12:38:25
Message: <44c3a601@news.povray.org>
// straight line segment evaluation
#macro Len_Spline(Espl begin_at stop_at num)
   #local c = 1/num;
   #local V1 = Espl(begin_at);
   #while (c <= 1)
      #local V2 = Espl( c*(stop_at - begin_at) + begin_at);
      vlength(V2-V1)+
      #local V1 = V2;
      #local c = c + 1/num;
   #end
   0
#end

#declare sample = Len_Spline(ABC_spl, 0, 0.5, 10000);


Post a reply to this message

From: Dave Matthews
Subject: Re: Subdividing a spline
Date: 24 Jul 2006 11:45:00
Message: <web.44c4ea4b3dd920ad3abc2b430@news.povray.org>
"Tim Attwood" <tim### [at] comcastnet> wrote:

(snip)

> #macro Split_Spline(SplA SplB begin_at stop_at rez stype)

(snip)

one small correction:

>        vstr(3, ABC_spl(c * (stop_at - begin_at) + begin_at),
>        ",", 0,3),">n");

should be:  vstr(3, SplA(c * (stop_at - begin_at) + begin_at,
etc.

Very nice!  I like the method (and Jim's as well.)  I've been puzzling over
an efficient approximation technique, also, for non-functionally defined
paths.

Thanks, both of you!

Dave Matthews


Post a reply to this message

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