POV-Ray : Newsgroups : povray.general : Strange behaviour on cubic_spline : Re: Strange behaviour on cubic_spline Server Time
1 Aug 2024 06:25:05 EDT (-0400)
  Re: Strange behaviour on cubic_spline  
From: Manuel Mata
Date: 13 Mar 2006 16:52:50
Message: <4415e9b2$1@news.povray.org>
> If you think you've found something odd with the behaviour of the 
> cubic-spline in 3.6, maybe post a short snippet of SDL to illustrate your 
> concern.

I'll post some code here down here. I'll explain it.
There are 4 points forming a path like a rectangle and 3 splines.
The yellow one is a closed cubic_spline.
With the green one I try to make a closed spline with straight stretchs, 
so I make 4 splines to build it, 2 linear_splines and 2 cubic_splines. 
The points should be tangent but they aren't. If you see the 2 
cubic_splines definition they only define a stretch and have 2 control 
points who should define the tangents at the points.
The blue spline is a simple cubic_spline. I try to draw it fully, from 
the first definition point to the last, but it only draws from the 
second to the last but one as you said before.

You can use camera 1 and 2 with the 'c' var at the end of the code to 
see the tangents. Here is the code.

I think I'm not doing anything badly ...

#version 3.6;
#include "colors.inc"

light_source{<0, 100, 0> White*1.5 parallel point_at <0,0,0>}
plane{y,0 pigment{checker White,Gray75}}

//axis
cylinder{0 x*100 0.1 pigment{Red}}
cylinder{0 z*100 0.1 pigment{Blue}}

//s: spline
//i: first point to draw
//j: last point to draw
//step: interval to place the object
//o: object to place (usually a sphere)
#macro drawSpline(s,i,j,step,o)
   union{
   #local counter = i;
   #while (counter <= j)
     object{o translate s(counter)}
     #local counter = counter + step;
   #end
   }
#end

//objects to draw splines
#declare yellowSphere = sphere{y*1 0.2 pigment{Yellow}}
#declare greenSphere = sphere{y*2 0.1 pigment{Green}}
#declare blueSphere = sphere{y*3 0.05 pigment{Blue}}

//points of spline
#declare p0 = <-6,0,4>;
#declare p1 = < 6,0,4>;
#declare p2 = < 6,0,-4>;
#declare p3 = <-6,0,-4>;

//red spheres to see the spline path
sphere{p0 0.3 pigment{Red}}
sphere{p1 0.3 pigment{Red}}
sphere{p2 0.3 pigment{Red}}
sphere{p3 0.3 pigment{Red}}

//
//splines
//

//from 0 to 3
#declare yellowSpline = spline{
cubic_spline
-1  p3,

0   p0,
1   p1,
2   p2,
3   p3,
4   p0,

5   p1
}

//from 0 to 1
#declare greenSpline_00 = spline{
linear_spline
0  p0,
1  p1,
}
//from 1 to 2
#declare greenSpline_01 = spline{
cubic_spline
0 p0,
1 p1,
2 p2,
3 p3
}
//from 2 to 3
#declare greenSpline_02 = spline{
linear_spline
2  p2,
3  p3,
}
//from 3 to 4
#declare greenSpline_03 = spline{
cubic_spline
2 p2,
3 p3,
4 p0,
5 p1
}



object{drawSpline(yellowSpline,0,4,0.005,yellowSphere)}

object{drawSpline(greenSpline_00,0,1,0.005,greenSphere)}
object{drawSpline(greenSpline_01,1,2,0.005,greenSphere)}
object{drawSpline(greenSpline_02,2,3,0.005,greenSphere)}
object{drawSpline(greenSpline_03,3,4,0.005,greenSphere)}

object{drawSpline(greenSpline_01,0,3,0.005,blueSphere)}

//c: cameras from 1 to 2
#declare c = 1;
#switch(c)
   #case(1) camera {orthographic location <0,15,0> look_at <0,0,0>} #break
   #case(2) camera {orthographic location <6,15,4> direction 3*z look_at 
p1} #break
#end


Post a reply to this message

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