POV-Ray : Newsgroups : povray.general : Subdividing a spline : Re: Subdividing a spline Server Time
31 Jul 2024 22:13:31 EDT (-0400)
  Re: Subdividing a spline  
From: Tim Attwood
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

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