POV-Ray : Newsgroups : povray.general : Converting bezier splines to regular splines : Re: Converting bezier splines to regular splines Server Time
31 Jul 2024 16:27:35 EDT (-0400)
  Re: Converting bezier splines to regular splines  
From: Charles C
Date: 12 Dec 2006 01:45:01
Message: <web.457e4efe6a30df8e9926319c0@news.povray.org>
"scam" <sca### [at] mailusydeduau> wrote:
> Hi.
>
> Can someone help me out with a macro that can convert bezier splines to
> regular splines? Something that can take as input:
>
> prism {
>     linear_sweep
>     bezier_spline
>     1.0, //top
>     0.0, //bottom
>     16, //nr points
>     /*   0*/ <202, 884>, <202, 884>, <508,884>, <508,884>,
>     /*   1*/ <508, 884>, <508, 884>, <508,602>, <508,602>
> }
>
> and output something like
>
> spline {
>     cubic_spline
>     0.0, <202, 0, 884>,
>     0.125, <202, 0, 884>,
>     0.25, <508, 0, 884>,
>     0.375, <508, 0, 884>,
>     0.5, <508, 0, 884>,
>     0.625, <508, 0, 884>,
>     0.75, <508, 0, 602>,
>     0.875, <508,602>
> }
>
> That is a macro that can take a prism containing a bezier_spline, and output
> a regular spline.
>
> My main problem is I don't know how to perform operations on POV-Ray objects
> to extract their underlying structure. Any help would be greatly
> appreciated.


I don't know how to either.  I hope you aren't dealing with a huge number of
items outputted by a modeler.  If there are few enough, I'd go ahead and
manually extract the splines.  Then you can make a macro which takes a
spline-identifier & interpolates along it.  Note that the following is
written in the web-form and so it's not tested.  I normally prefer
cubic_splines like your sample output but then you've got to deal with
adding the tangents on the end...  Not too hard though because you've got
that info
from the bezier points.  I just need to get to sleep.

#macro Bezier_To_Natural(TheBezierSpline,From_Point,To_Point,Frequency)
   #local Ctr= From_Point;
   spline{ natural_spline
     #while(Ctr <= To_Point)
        Ctr,                  //value along spline
        TheBezierSpline(Ctr), //defining point
        #local Ctr = Ctr+(1/Frequency);
     #end //end while
#end //end macro


Charles


PS, did you want the output as text, or just a spline equivalent to your
example?


Post a reply to this message

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