A parametric cubic polynomial is the lowest-order formulation that can insure continuity of position, slope, and curvature where two such curves meet. A curve section is specified witha set of four `guide coordinates' and a `curve basis' defining how the guide points influence the shape of the curve. A B-spline curve is constrained to have continuous first and second derivatives where adjacent curve sections meet. The B-spline curves do not, in general, pass through their guide coordinates.
The matrix algebra follows the IRIS manual and Clark (1981). A 4 x 4 matrix, M, is computed from guide coordinates, the curve basis, and the desired sampling as follows: M = SBG.
If N line segments are desired to approximate the curve section, the sampling matrix is given by:
S = { 6/N**3 0 0 0 }
{ 6/N**3 2/N**2 0 0 }
{ 1/N**3 1/N**2 1/N 0 }
{ 0 0 0 1 }
The basis matrix for a cubic B-spline is given by:
B = 1/6 { -1 3 -3 1 }
{ 3 -6 3 0 }
{ -3 0 3 0 }
{ 1 4 1 0 }
The geometry matrix is constructed from the guide coordinates as:
G = { x_1 y_1 z_1 1.0 }
{ x_2 y_2 z_2 1.0 }
{ x_3 y_3 z_3 1.0 }
{ x_4 y_4 z_4 1.0 }
The line segments are now generated with the `forward difference algorithm' given in the C language below:
/* Comments:
*
* M[4][4] is the current matrix ( indexed 0..3 )
* N is the number of line segments to be drawn
* MoveTo() and DrawTo() represent generic graphics calls
*/
MoveTo( M[3][0]/M[3][3], M[3][1]/M[3][3], M[3][2]/M[3][3] );
for( k=0; k<N; k=k+1 ) {
for( i=3; i>0; i=i-1 ) {
for( j=0; j<4; j=j+1 ) {
M[i][j] = M[i][j] + M[i-1][j];
}
}
DrawTo( M[3][0]/M[3][3], M[3][1]/M[3][3], M[3][2]/M[3][3] );
}
Thus if guide coordinates x_1,x_2,x_3,x_4 are used to create the first section of the curve, the coordinates x_2,x_3,x_4,x_5 will create the next curve section, smoothly joining the first.