Splines are a mathematical means of representing a curve, by specifying a series of points at intervals along the curve and defining a function that allows additional points within an interval to be calculated. There are various functions available to approximate a curve, but in this article we will focus on a variety of spline known as the Catmull-Rom spline.
The points that define a spline are known as "Control Points". One of the features of the Catmull-Rom spline is that the specified curve will pass through all of the control points - this is not true of all types of splines.
This formula gives Catmull-Rom spline the following characteristics:
While a spline segment is defined using four control points, a spline may have any number of additional control points. This results in a continuous chain of segments, each defined by the two control points that form the endpoints of the segments, plus an additional control point on either side of the endpoints. Thus for a given segment with endpoints Pn and Pn+1, the segment would be calculated using [Pn-1, Pn, Pn+1, Pn+2].
Because a segment requires control points to the outside of the segment endpoints, the segments at the extreme ends of the spline cannot be calculated. Thus, for a spline with control points 1 through N, the minimum segment that can be formulated is P1<->P2, and the maximum segment is PN-3<->PN-2. Thus, to define S segments, S+3 control points are required.
Support of Catmull-Rom Splines in DirectX
The D3DX math libraries provide functions for calculating a point on a Catmull-Rom segment, using 2D, 3D, or 4D vectors. These functions are:
Each of these functions accepts four control points and a positional weight from 0.0 to 1.0, and returns an interpolated vector . The returned value will fall in the range of *pV2 (when s==0.0) to *pV3 (when s==1.0).
Sample: Path Interpolation using Catmull-Rom Splines
Visitors Since 1/1/2000: