Handout 37

Drawing Complex Objects Using Splines*


Splines give you a way to define 'pathways' through your scenes. You specify a series of points, and POV-Ray interpolates to make a curve connecting them. Every point along the spline has a numerical value. A good example of a spline is the path of a moving object: the spline itself would be the path traced out by the object and the 'parameter' would be time; as time changes the object's position moves along the spline. Therefore, given a time reference you could use this spline to find the position of the object. In fact, splines are very well suited to animation.

The syntax is:

SPLINE_DECLARATION:
  #declare IDENTIFIER =
    spline {
      [SPLINE_IDENTIFIER] |
      [SPLINE_TYPE] |
      [Val_1, <Point_1>[,]
       Val_2, <Point_2>[,]
       ...
       Val_n, <Point_n>]
    }

SPLINE_TYPE:
  linear_spline | quadratic_spline | cubic_spline | natural_spline

SPLINE_USAGE:
  MySpline(Val) | MySpline(Val, SPLINE_TYPE)

The first item gives the type of interpolation.
In a linear_spline, straight lines connect each point.
In a quadratic_spline, a smooth curve defined by a second-order polynomial connects each point.
In cubic_spline and natural_spline, a smooth curve defined by a third-order polynomial connects each point.
The default is linear_spline.

Following this are a number of float values each followed by a position vector, all separated by commas. Val_1, Val_2, etc, are the value of the spline parameter at each specific point. The points need not be in order of their parameter values. If two points have the same parameter value, the second point will replace the first. Beyond the range of the lowest and highest parameter values, the spline position is fixed at the endpoints.

Example (roller coaster)

#include "colors.inc"   
#include "axes.inc"    
#include "skies.inc"             

global_settings { assumed_gamma 1.2 }
        
light_source {<0,23,0> White * 1 shadowless}
light_source {<0,0,-5> White * 1 shadowless}    

sky_sphere { S_Cloud2 }  //Sky    
plane {y,-5 pigment {MediumForestGreen}}    // Ground
        
// draw the axes      
object{ AxisXYZ(10, 10, 10, Texture_A_Dark, Texture_A_Light)  }      

#declare MySpline =
  spline {
    cubic_spline
    -.25, <-8,0,0>
    0.00, <-8,0,0>
    0.25, <-8,8,-8>
    0.50, <0,3,-6>
    0.75, <7,0,-2>
    1.00, <10,5,4>
    1.25, <8,3,4>
    1.50, <6,0,6>
    1.75, <0,0,10>
    2.00, <-2,0,10>
    2.25, <-4,0,10>
    2.50, <-6,0,10>
    2.75, <-8,0,0>
    3.00, <-8,0,0>
  }
       
// draw the tracks
#declare ctr = 0;
#while (ctr < 3)
  sphere {
    MySpline(ctr),.05
    pigment { rgb <0,0,0> }
  }
  
  sphere {
    MySpline(ctr),.05
    pigment { rgb <0,0,0> }
    scale .97
  }
  
  #declare ctr = ctr + .001;
#end

// move the camera over the tracks
camera
{ angle 0
  location MySpline(clock * 3) + <0,.5,0>    // make my location above the tracks  
  look_at  MySpline(clock * 3 + 0.01) + <0,.6,0> // look a little ahead and up 
}               

PovRay Source File axes.inc


* portions from PovRay Help.