HowTo:Use Splines and Bezier Curves

From POV-Wiki
Jump to navigation Jump to search

Introduction

All Curves and Patches utilised by POVRay are influenced by a number of control points. All curves pass through the start and the end control point, while most of the curves pass through the intermediate control points.

Splines

Splines may be of Linear, Quadratic or Cubic type of Spline and are accessed with the command #spline as shown below.

#declare MYSPLINE = spline {
    cubic_spline
    -1,  <-1,0,0>
     0,  <2,-1,0>
     1,  <3,-1,2>
     2,  <5,0,5>
     3,  <3,3,3>
     4,  <2,2,2>
     5,  <2,-1,0>
     6,  <3,-1,2>
     7,  <5,0,5>
}

#declare count = 0;
#while (count <= 5)
  #sphere {  MYSPLINE (count), 0.25 pigment {Blue} }
  #declare count = count + 0.01;
#end

All "spline" type splines pass through the intermediate control points, these are:

  1. A linear spline will move linearly from one control point to the next.
  2. A Quadratic Spline will pass from one point to the next with reference only to where it is going.
  3. A Cubic Spline will pass from one control point to the next with reference to where it cam from and where it will go to next.

The important thing to remember about using splines is that as the control number exceeds a control point, the next increment of control points is taken to control the path of the spline. Sufficient control points need to be defined otherwise POVRay will yield an error or misrepresent the scene.

Bezier Curves

Bezier Curves differ from other types of spline in that they only pass through the first and last control point and are simply influenced by the other intermediate control points. The equation for a bezier curve as used by POVRay is cubic and is of the form.

where t is from 0 to 1 and A, B, C and D represent a variable that may be a scalar or vector.

Consecutive bezier curves may be placed one after the other however the direction of the tangents at the start and end control point of joining curves must be identical.

About Bicubic Patches

If a Bezier curve is a 1 dimensional line on three dimensional space, then a bicubic patch is a 2 dimensional sheet on a three dimensional plane.

The bezier patch has only four fixed points that is controlled by 12 reference points.

#bicubic_patch {
  type 1 flatness 1 u_steps 3  v_steps 3
  <0, 0, 2> <1, 0, 0> <2, 0, 0> <3, 0, -2>
  <0, 1, 0> <1, 1, 0> <2, 1, 0> <3, 1,  0>
  <0, 2, 0> <1, 2, 0> <2, 2, 0> <3, 2,  0>
  <0, 3, 2> <1, 3, 0> <2, 3, 0> <3, 3, -2>
}