B-Splines

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

A B-spline curve is a smooth parametric curve \(C(t)\) shaped by control points \(P_1,\ldots,P_n\): the points steer the curve, but it need not pass through them. A curve of order \(k\) (degree \(k-1\)) is a weighted sum of the control points and basis functions \(N_{i,k}(t)\) defined over a nondecreasing knot vector \(t_1\le t_2\le\cdots\le t_{n+k}\):

\[ C(t)=\sum_{i=1}^{n} P_i\,N_{i,k}(t), \qquad t_k\le t\le t_{n+1}. \]

The basis functions come from the Cox-de Boor recursion, starting from indicators of the knot spans:

\[ N_{i,1}(t)=\begin{cases}1, & t_i\le t<t_{i+1},\\ 0, & \text{otherwise,}\end{cases} \qquad N_{i,k}(t)=\frac{t-t_i}{t_{i+k-1}-t_i}\,N_{i,k-1}(t)+\frac{t_{i+k}-t}{t_{i+k}-t_{i+1}}\,N_{i+1,k-1}(t), \]

where a zero-denominator term (a repeated knot) is taken as zero, and the last non-empty span includes \(t_{n+1}\). Both animations use cubic B-splines (\(k=4\), basis functions \(N_{i,4}\)), \(n=7\) control points and the clamped knot vector \((0,0,0,0,1,2,3,4,4,4,4)\), so \(t\) runs over \([0,4]\).

The construction needs \(n\ge k\) control points and \(n+k\) knots. In general, each \(N_{i,k}\) is non-negative and zero outside \([t_i,t_{i+k}]\), and the basis functions sum to 1 on \([t_k,t_{n+1}]\) (partition of unity, Case 2). So on each knot span the curve lies in the convex hull of the \(k\) control points active there, and moving one control point changes the curve only where its basis function is non-zero (local support). At an interior knot of multiplicity \(m\le k-1\) the curve is at least \(C^{k-1-m}\), so a cubic with simple interior knots, as here, is \(C^2\). A clamped knot vector repeats its first and last knots \(k\) times, and the curve then starts at \(P_1\) and ends at \(P_n\), tangent there to the control polygon.

A B-spline curve has no convergence order, since it follows its control polygon rather than interpolating data. Used instead to interpolate equally spaced data, as in Mathews’ module, B-splines give a cubic spline, whose error is in general \(O(h^4)\) for \(f\in C^4[a,b]\) with clamped end conditions.

The control points are not points on the curve. In Case 1 the curve misses each interior control point by 0.68 to 1.21, and although \(P_3=(2,-1)\) and \(P_5=(4,-0.5)\) lie below the \(x\)-axis, the curve has \(y>0\) for all \(0<t<4\). Local support is weak with few knot spans: here \(N_{4,4}\) is non-zero on all of \((0,4)\), so moving \(P_4\) moves every point except the ends. Code that keeps every span half-open makes every basis function zero at \(t=4\), so direct evaluation gives \(C(4)=(0,0)\) instead of \(P_7=(6,0)\); the page’s scripts stop at \(t=4-10^{-9}\).

With four control points and knots \((0,0,0,0,1,1,1,1)\), a cubic B-spline curve is exactly the cubic Bézier curve, and Mathews’ B-spline construction is another route to the interpolating Cubic Splines.

Animations

These animations show two complementary views of cubic B-splines: the smooth curve traced from control points, and the individual basis functions \(N_{i,4}(t)\) whose weighted sum defines the curve.

Julia source scripts that generated these animations are linked under each case.

Case 1 — Cubic B-spline curve traced from 7 control points

Behavior: A cubic B-spline curve with a clamped knot vector passes through the first and last control points and is smoothly pulled toward the interior control points. The curve is \(C^2\)-continuous everywhere. The animation traces the curve parameter \(t\) from start to end.

Julia source

Cubic B-spline curve traced from 7 control points by summing Cox–de Boor basis functions; it passes through only the first and last control points and lies within the convex hull of the control polygon

Case 2 — Basis functions \(N_{1,4}, \ldots, N_{7,4}\) and the partition of unity

Behavior: Each cubic B-spline basis function \(N_{i,4}(t)\) is non-negative and is zero outside \([t_i, t_{i+4}]\), which is at most 4 knot spans. With the clamped knot vector \((0,0,0,0,1,2,3,4,4,4,4)\), the repeated end knots shrink \(N_{1,4},\ldots,N_{7,4}\) to 1, 2, 3, 4, 3, 2 and 1 non-zero spans; only \(N_{4,4}\) covers all 4. Their sum equals 1 everywhere in the domain (partition of unity), which is why the B-spline curve lies within the convex hull of the control polygon.

Julia source

Seven cubic B-spline basis functions N_{i,4} revealed one at a time; running sum shown in black approaches 1 as all functions are added

Unlike this page, which uses a clamped knot vector to define parametric B-spline curves, the B-Splines module of the cited Mathews site uses cubic B-splines for interpolation: its Example 1 builds the natural cubic spline through equally spaced data points as a weighted sum of translated copies of one cubic B-spline, with the weights found by solving a linear system, and its Example 2 graphs those translated B-splines, the weighted terms and their partial sums; neither example is animated here. On this page the weights are the given control points, so no linear system is solved and the two animations concentrate on the curve and the basis functions that form it.

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.