Mathematical Principles

The following chapter describes some basics about splines and how to use them in TinySpline. At first, we start with a mathematical examination of NURBS, B-Splines, Bézier curves, lines, and points. The given code examples are using the C interface.

Let \(\supset\) be the superset relation so that we can write \(A \supset B\) in case of two sets \(A, B\) with \(A\) being the superset of \(B\). Furthermore, we define the following sets of splines:

  • \(\text{NURBS}\)
    The set of all NURBS curves.
  • \(\text{BSPLINES}\)
    The set of all B-Spline curves.
  • \(\text{BEZIERS}\)
    The set of all Bézier curves.
  • \(\text{LINES}\)
    The set of all lines.
  • \(\text{POINTS}\)
    The set of all points.

Then, the following equation holds:

$$\text{NURBS} \supset \text{BSPLINES} \supset \text{BEZIERS} \supset \text{LINES} \supset \text{POINTS}.$$

To put it differently, we can say that every point is a line, every line is a Bézier curve, every Bézier curve is a B-Spline, and ever B-Spline is a NURBS. In order to understand this relation, we will start with a (simple) definition of B-Splines that is more code- than maths-related.

A B-Spline \(b\) consists of four attributes:

  1. The degree of \(b\) describing the (general) smoothness of \(b\).
  2. The control points of \(b\) used to shape \(b\).
  3. The knot vector of \(b\) (simply knots) used to define the continuity of \(b\) at certain points (not the control points!).
  4. The dimension of \(b\) defining how many components each control point has (for instance, (x, y) in 2D).

A B-Spline \(b\) of degree \(p\) with \(m\) control points has \(n = m+p+1\) knots. The knot vector \(knots\) must be in ascending order (monotonically increasing). That is, \(u_i \leq u_{i+1}\) for all knot values \(u\) in \(knots\) and \(0 \leq i < n-1\). The domain of \(b\) is given by \(u_p\) and \(u_{n-p}\). That means, one can retrieve points laying on \(b\) by evaluating \(b\) at any knot value \(u\) with \(u_p \leq u \leq u_{n-p}\). The evaluation of \(b\) at \(u\) is denoted by \(b(u)\).

The following example illustrates the domain of B-Splines. Let's say \(b\) is a B-Spline of degree 3 (cubic B-Spline) with the following knot vector:

$$knots = [4, 5, 6, 10, 11, 11, 18, 19, 20]$$

This implies that \(p = 3\), \(n = 9\), and \(m = n-p-1 = 9-3-1 = 5\). The domain of \(b\) is \([6, 18]\) so that \(b\) can be evaluated at any knot value \(u\) with \(6 \leq u \leq 18\), for instance, \(6, 6,1316, 11, 17,999999, 18\) and so on. As you may have noticed, the knot value \(11\) occurs twice in \(knots\). Repeating knot values is permitted in principle, but is limited to the degree of a B-Spline (as we will see in the following definition).

Given a B-Spline \(b\) of degree \(p\) with knot vector \(knots\), the multiplicity \(s(u)\) of any \(u \in knots\) is limited by the order (\(p+1\)) of \(b\). That is, \(\forall u \in knots: s(u) \leq p+1\). Furthermore, \(b\) is \(C^{p-s(u)}\) continuous at \(u\) so that increasing \(s(u)\) by \(1\) decreases \(b\)'s continuity at \(u\) by \(1\).

That said, you will notice that B-Splines are discontinuous (\(C^{-1}\) continuous) at certain points if the corresponding knot values have multiplicity \(p+1\). Evaluating a B-Spline \(b\) at \(u\) with \(s(u) = p+1\) almost always returns two points \(q, r\) rather than one, though \(q\) and \(r\) may be the same point. As if all this wasn't complicated enough, there is a special case in which evaluating \(b\) always returns a single point regardless of \(b\)'s continuity at this point. It occurs when the evaluated point is the very first or rather very last point of a B-Spline (you can think of a B-Spline's ending points).

To be continued