Solution (source code)

= Solution

Write a degree-$p$ <B-spline> as $C(t)=\sum_iP_iN_{i,p}(t)$ and locate its <spline knot> span. There are several equivalent exact evaluation methods.

Evaluate the at most $p+1$ nonzero basis functions by the <Cox-de Boor recurrence>, then form their weighted sum of control points. Alternatively apply <De Boor's algorithm> directly to the $p+1$ active control points. In a span $[t_k,t_{k+1})$, initialize $d_j^{(0)}=P_{k-p+j}$ and repeatedly interpolate:
$$
d_j^{(r)}=(1-\alpha_{j,r})d_{j-1}^{(r-1)}+\alpha_{j,r}d_j^{(r-1)},\qquad \alpha_{j,r}=\frac{t-t_{k-p+j}}{t_{k+1+j-r}-t_{k-p+j}},
$$
for $r=1,\ldots,p$ and $j=p,p-1,\ldots,r$. The last point $d_p^{(p)}$ is $C(t)$; zero knot intervals are handled by the standard limiting convention or an appropriate neighboring nonempty span.

A third method precomputes the local polynomial coefficients on each span and evaluates them by <Horner's method>. For a uniform cubic <B-spline>, a fixed four-by-four basis matrix gives these coefficients. A fourth method uses <knot insertion> to express the relevant span as a <Bézier curve>, followed by <De Casteljau's algorithm>. Both interpolation algorithms also split the curve at the requested parameter. Repeated subdivision supplies arbitrarily accurate polygonal evaluation, although a finite subdivision mesh is generally an approximation rather than the exact requested point. \b[Basis summation, de Boor interpolation, local polynomial evaluation and Bézier extraction are equivalent exact representations.]