POV-Ray : Newsgroups : povray.general : Splines and Splines Server Time
24 Dec 2024 12:44:57 EST (-0500)
  Splines and Splines (Message 1 to 4 of 4)  
From: TheOzule
Subject: Splines and Splines
Date: 18 Jan 2008 06:10:01
Message: <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.  Then I saw that I
could #declare a spline, but then found the radically different syntax:

     PointCount
     Float, <Point>   // repeated

versus

     <point>          // repeated

Obviously it's too late to use a different keyword for the #declared spline, but
maybe it would be possible to have a new object, perhaps called a spline_shape,
that could be #declared:

     #declare Fred = spline_shape { SPLINE_TYPE POINTs ... }

and it could be used in things like lathes:

     lathe { ... spline_shape { Fred } ... }

This would allow libraries of spline_shapes to be created (table legs, newel
posts, architrave, etc..) and to be referenced, which does not seem to be
possible at present.

Cheers

Chris


Post a reply to this message

From: Chris B
Subject: Re: Splines and Splines
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

From: Chris B
Subject: Re: Splines and Splines
Date: 18 Jan 2008 07:02:03
Message: <4790953b$1@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote in message 
news:47909471$1@news.povray.org...
>

> 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>

Whoops, that should read:
  I, MyPointArray[I]

>    #local I = I + 1;
>  #end
> }


Post a reply to this message

From: TheOzule
Subject: Re: Splines and Splines
Date: 18 Jan 2008 11:15:00
Message: <web.4790cfbd2d0e05211216ac780@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> "Chris B" <nom### [at] nomailcom> wrote in message
> news:47909471$1@news.povray.org...
.... snip
> Whoops, that should read:
>   I, MyPointArray[I]
>
> >    #local I = I + 1;
> >  #end
> > }

Chris,

Very many thanks - I thought I must be missing something.  I'll try to retrace
the steps that gave the error to see what I did wrong, but the solution was
what I was after!

Cheers

Chris O


Post a reply to this message

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