How to construct a parametric cubic B spline?

Solution 1:

If you want to use the points $\mathbf{P}_0, \ldots, \mathbf{P}_n$ as control points of a spline curve, then the curve is just $$ \mathbf{C}(t) = \sum_{i=0}^n B_i(t)\mathbf{P}_i $$ where the $B_i$ are b-spline basis functions. This formula allows you to compute points on the curve, which you can then use to draw it. Note that, in general, this curve will not pass through the points $\mathbf{P}_0, \ldots, \mathbf{P}_n$.

If you want your curve to pass through the points $\mathbf{P}_0, \ldots, \mathbf{P}_n$, then you first need to construct an interpolating spline.

You will need to use a parametric spline that gives $x$ and $y$ as functions of some parameter $t$. To construct the curve, you must first assign a parameter value $t_i$ to each point $P_i$. These parameter values are entirely fabricated -- they are not an intrinsic part of the original interpolation problem. Furthermore, different choices for these parameter values will produce significantly different curves. The usual approach is to choose them so that $t_{i+1}-t_i$ is equal to the chord-length between the points $\mathbf{P}_i$ and $\mathbf{P}_{i+1}$.

You solve systems of linear equations to get the $x$ and $y$ coordinates of control points $\mathbf{Q}_0, \ldots, \mathbf{Q}_n$. Then the equation of the curve is again $$ \mathbf{C}(t) = \sum_{i=0}^n B_i(t)\mathbf{Q}_i $$

Note that we haven't really made use of the fact that the points $\mathbf{P}_i$ or $\mathbf{Q}_i$ are 2D; this same construction will work in 3D, or in fact in any finite-dimensional space.

A good reference is this web site.