Point p5, which is identical to p1, is needed to close the shape. Thus, n = 5. The values of s are easy – since the points are all equidistant, by inspection: s = [0, 0.25, 0.5, 0.75, 1]T.
Boundary conditions require special consideration. In the case of a closed loop, the 1st and last points are joined, which makes them interior points subject to the same 1st and 2nd derivative compatibility constraints as the other interior points. Thus, with closed loops, there are no choices to be made for boundary conditions! To derive the 1st derivative compatibility equation, simply equate 1st derivatives of p1 and p5:
The 2nd derivative boundary conditions are easy: p1" - p5" = 0. (Note: using p just means there are 2 sets of equations, one for x and another for y). Also, h1 = h2 = h3 = h4 = h = s2 = 0.25, which allows the use of the simplified equations. The resulting matrix equation to be solved is:
Code:
Matrix Equation
The solution is x" = [-48, 0, 48, 0, -48]T and y" = [0, -48, 0, 48, 0]T, from which we can calculate the coefficients of the spline segments and generate the plot using s = 0 to 1. It is a remarkable fit considering only 4 spline segments were used. Clearly, more points will result in an even better fit.
Conclusion:
We have extended our knowledge of cubic splines to include the powerful and flexible parametric version and have fit various shapes (including approximating a circle) to a set of given points.
Code:
****************************
* Plot here
****************************
Last edited by VBAhack; Jul 30th, 2007 at 03:44 PM.