POV-Ray : Newsgroups : povray.general : Splines and Splines : Re: Splines and Splines Server Time
31 Jul 2024 02:29:22 EDT (-0400)
  Re: Splines and Splines  
From: Chris B
Date: 18 Jan 2008 06:58:41
Message: <47909471$1@news.povray.org>
"TheOzule" <chr### [at] chris-oslandorguk> wrote in message 
news:web.4790885a62368d6f8c76e7b20@news.povray.org...
>I hope I'm not retreading old ground here ...
>
> I'm puzzled why 'spline' is used in two radically different senses in 
> POV-Ray.
>
> In something like 'lathe' it is what I regard as its normal use; it 
> produces a
> bent object in 3D.
>
> In a #declare I would consider it a lookup function; it produces a float.
>
> I hit this by wanting to include a spline in a lathe, where the spline was
> created by another program.  I tried
>
> lathe { linear_spline
> #include "spline.dat"
>       }
>
> but that got thrown out with '#' found when '}' expected.

Hi Chris,

I think POV-Ray already does everything you're asking for.

I'm not sure why you've got the particular error that you did, but that 
include statement should work so long as the syntax is right once the main 
file and the included file are combined. I suspect that you may have a '#' 
character somewhere inside the include file that it was complaining about. 
Try:

light_source { <-10,100,-6>, rgb 1 }
camera {location <-9, 10, -10> look_at 0}
lathe { linear_spline
  5,
  #include "spline.dat"
  pigment {rgb <1,0,0>}
}

where spline.dat contains
<2, 0>, <3, 0>, <3, 5>, <2, 5>, <2, 0>
It just worked fine for me.
I also tried it with the number of points (5) being defined within the 
include file instead of in the main file and that worked too.

> Then I saw that I
> could #declare a spline, but then found the radically different syntax:
>
>     PointCount
>     Float, <Point>   // repeated
>
> versus
>
>     <point>          // repeated
>

The spline definition creates a 3D spline rather than the 2D spline used in 
the lathe object and incorporates a float that I like to think of as the 
distance along the spline.

To convert between the formats is very easy, you could read your include 
file into an array

#declare MyPointArray = array[5] {
  <2, 0, 0>, <3, 0, 0>, <3, 5, 0>, <2, 5, 0>, <2, 0, 0>
};

Then you can use the array in either a spline definition:

#declare MySpline = spline {
  #local I = 0;
  #while (I<5)
    I, <MyPointArray[I].x,MyPointArray[I].x>
    #local I = I + 1;
  #end
}

Or you can use just two dimensions of the 3D vector array in a lathe 
definition:

lathe {
  linear_spline
  5,
  #local I = 0;
  #while (I<5)
    <MyPointArray[I].x,MyPointArray[I].y>
    #local I = I + 1;
  #end
  pigment {rgb <1,0,0>}
}

I think this does more or less the same as the pseudo code in your question 
and I hope you can pluck something useful out of this range of alternatives.

Regards
Chris B.


Post a reply to this message

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