Spline (mathematics)



In mathematics, a spline is a function defined piecewise by polynomials. In interpolating problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results, even when using low degree polynomials, while avoiding Runge's phenomenon for higher degrees.

In the computer science subfields of computer-aided design and computer graphics, the term spline more frequently refers to a piecewise polynomial (parametric) curve. Splines are popular curves in these subfields because of the simplicity of their construction, their ease and accuracy of evaluation, and their capacity to approximate complex shapes through curve fitting and interactive curve design.

The term spline comes from the flexible spline devices used by shipbuilders and draftsmen to draw smooth shapes.

Introduction
The term "spline" is used to refer to a wide class of functions that are used in applications requiring data interpolation and/or smoothing. The data may be either one-dimensional or multi-dimensional. Spline functions for interpolation are normally determined as the minimizers of suitable measures of roughness (for example integral squared curvature) subject to the interpolation constraints. Smoothing splines may be viewed as generalizations of interpolation splines where the functions are determined to minimize a weighted combination of the average squared approximation error over observed data and the roughness measure. For a number of meaningful definitions of the roughness measure, the spline functions are found to be finite dimensional in nature, which is the primary reason for their utility in computations and representation. For the rest of this section, we focus entirely on one-dimensional, polynomial splines and use the term "spline" in this restricted sense.

History
According to Gerald Farin, B-splines were explored as early as the nineteenth century by Nikolai Lobachevsky at Kazan University in Russia.

Before computers were used, numerical calculations were done by hand. Although piecewise-defined functions like the sign function or step function were used, polynomials were generally preferred because they were easier to work with. Through the advent of computers, splines have gained importance. They were first used as a replacement for polynomials in interpolation, then as a tool to construct smooth and flexible shapes in computer graphics.

It is commonly accepted that the first mathematical reference to splines is the 1946 paper by Schoenberg, which is probably the first place that the word "spline" is used in connection with smooth, piecewise polynomial approximation. However, the ideas have their roots in the aircraft and shipbuilding industries. In the foreword to (Bartels et al., 1987), Robin Forrest describes "lofting", a technique used in the British aircraft industry during World War II to construct templates for airplanes by passing thin wooden strips (called "splines") through points laid out on the floor of a large design loft, a technique borrowed from ship-hull design. For years the practice of ship design had employed models to design in the small. The successful design was then plotted on graph paper and the key points of the plot were re-plotted on larger graph paper to full size. The thin wooden strips provided an interpolation of the key points into smooth curves. The strips would be held in place at discrete points (called "ducks" by Forrest; Schoenberg used "dogs" or "rats") and between these points would assume shapes of minimum strain energy. According to Forrest, one possible impetus for a mathematical model for this process was the potential loss of the critical design components for an entire aircraft should the loft be hit by an enemy bomb. This gave rise to "conic lofting", which used conic sections to model the position of the curve between the ducks. Conic lofting was replaced by what we would call splines in the early 1960s based on work by J. C. Ferguson at Boeing and (somewhat later) by M.A. Sabin at British Aircraft Corporation.

The word "spline" was originally an East Anglian dialect word.

The use of splines for modeling automobile bodies seems to have several independent beginnings. Credit is claimed on behalf of de Casteljau at Citroën, Pierre Bézier at Renault, and Birkhoff, Garabedian, and de Boor at General Motors (see Birkhoff and de Boor, 1965), all for work occurring in the very early 1960s or late 1950s. At least one of de Casteljau's papers was published, but not widely, in 1959. De Boor's work at General Motors resulted in a number of papers being published in the early 1960s, including some of the fundamental work on B-splines.

Work was also being done at Pratt & Whitney Aircraft, where two of the authors of (Ahlberg et al., 1967) — the first book-length treatment of splines — were employed, and the David Taylor Model Basin, by Feodor Theilheimer. The work at General Motors is detailed nicely in (Birkhoff, 1990) and (Young, 1997). Davis (1997) summarizes some of this material.

Definition
We begin by limiting our discussion to polynomials in one variable. In this case, a spline is a piecewise polynomial function. This function, call it $S$, takes values from an interval $C^{2}$ and maps them to $$\R,$$ the set of real numbers, $$S: [a,b] \to \R.$$ We want $S$ to be piecewise defined. To accomplish this, let the interval $[a,b]$ be covered by $k$ ordered, disjoint subintervals,

$$\begin{align} &[t_i, t_{i+1}], \quad i = 0,\ldots, k-1 \\[4pt] &[a,b] = [t_0,t_1) \cup [t_1,t_2) \cup \cdots \cup [t_{k-2},t_{k-1}) \cup [t_{k-1},t_k) \cup [t_k] \\[4pt] &a = t_0 \le t_1 \le \cdots \le t_{k-1} \le t_k = b \end{align}$$

On each of these $k$ "pieces" of $[a,b]$, we want to define a polynomial, call it $Pi$. $$P_i: [t_i, t_{i+1}]\to \R.$$ On the $i$th subinterval of $[a,b]$, $S$ is defined by $Pi$,

$$\begin{align} S(t) &= P_0 (t), && t_0 \le t < t_1, \\[2pt] S(t) &= P_1 (t), && t_1 \le t < t_2, \\ &\vdots \\ S(t) &= P_{k-1} (t), && t_{k-1} \le t \le t_k. \end{align}$$

The given $[a,b]$ points $ti$ are called knots. The vector $k + 1$ is called a knot vector for the spline. If the knots are equidistantly distributed in the interval $t = (t0, …, tk)$ we say the spline is uniform, otherwise we say it is non-uniform.

If the polynomial pieces $Pi$ each have degree at most $n$, then the spline is said to be of degree $[a,b]$ (or of order $&le; n$).

If $$S\in C^{r_i}$$ in a neighborhood of $ti$, then the spline is said to be of smoothness (at least) $$C^{r_i}$$ at $ti$. That is, at $ti$ the two polynomial pieces $n + 1$ and $Pi$ share common derivative values from the derivative of order 0 (the function value) up through the derivative of order $ri$ (in other words, the two adjacent polynomial pieces connect with loss of smoothness of at most $P_{i–1}$)

$$\begin{align} P_{i-1}^{(0)}(t_i) &= P_i^{(0)} (t_i), \\[2pt] P_{i-1}^{(1)}(t_i) &= P_i^{(1)} (t_i), \\ \vdots& \\ P_{i-1}^{(r_i)}(t_i) &= P_i^{(r_i)} (t_i). \end{align}$$

A vector $n – r_{i}$ such that the spline has smoothness $$C^{r_i}$$ at $ti$ for $r = (r1, …, rk–1)$ is called a smoothness vector for the spline.

Given a knot vector $i = 1, …, k – 1$, a degree $n$, and a smoothness vector $t$ for  $r$, one can consider the set of all splines of degree $t$ having knot vector $&le; n$ and smoothness vector  $t$. Equipped with the operation of adding two functions (pointwise addition) and taking real multiples of functions, this set becomes a real vector space. This spline space is commonly denoted by $$S^{\mathbf r}_n(\mathbf  t).$$

In the mathematical study of polynomial splines the question of what happens when two knots, say $ti$ and $r$, are taken to approach one another and become coincident has an easy answer. The polynomial piece $t_{i+1}$ disappears, and the pieces $Pi(t)$ and $P_{i−1}(t)$ join with the sum of the smoothness losses for $t_{i}$ and $P_{i+1}(t)$. That is, $$ S(t) \in C^{n-j_i-j_{i+1}} [t_i = t_{i+1}],$$ where $t_{i+1}$. This leads to a more general understanding of a knot vector. The continuity loss at any point can be considered to be the result of multiple knots located at that point, and a spline type can be completely characterized by its degree $n$ and its extended knot vector

$$ (t_0, t_1 , \cdots , t_1 , t_2, \cdots , t_2 , t_3 , \cdots , t_{k-2} , t_{k-1} , \cdots , t_{k-1} , t_k) $$

where $ti$ is repeated $j_{i}$ times for $ji = n – ri$.

A parametric curve on the interval $i = 1, …, k – 1$ $$G(t) = \bigl( X(t), Y(t) \bigr), \quad t \in [ a, b ]$$ is a spline curve if both $X$ and $Y$ are spline functions of the same degree with the same extended knot vectors on that interval.

Examples
Suppose the interval $[a,b]$ is $[a, b]$ and the subintervals are $[0, 3]$. Suppose the polynomial pieces are to be of degree 2, and the pieces on $[0, 1], [1, 2], [2, 3]$ and $[0, 1]$ must join in value and first derivative (at $[1, 2]$) while the pieces on $t = 1$ and $[1, 2]$ join simply in value (at $[2, 3]$). This would define a type of spline $t = 2$ for which

$$\begin{align} S(t) &= P_0 (t) = -1+4t-t^2, && 0 \le t < 1 \\[2pt] S(t) &= P_1 (t) = 2t, && 1 \le t < 2 \\[2pt] S(t) &= P_2 (t) = 2-t+t^2, && 2 \le t \le 3 \end{align}$$

would be a member of that type, and also

$$\begin{align} S(t) &= P_0 (t) = -2-2t^2, && 0 \le t < 1 \\[2pt] S(t) &= P_1 (t) = 1-6t+t^2, && 1 \le t < 2 \\[2pt] S(t) &= P_2 (t) = -1+t-2t^2, && 2 \le t \le 3 \end{align}$$

would be a member of that type. (Note: while the polynomial piece $S(t)$ is not quadratic, the result is still called a quadratic spline. This demonstrates that the degree of a spline is the maximum degree of its polynomial parts.) The extended knot vector for this type of spline would be $2t$.

The simplest spline has degree 0. It is also called a step function. The next most simple spline has degree 1. It is also called a linear spline. A closed linear spline (i.e, the first knot and the last are the same) in the plane is just a polygon.

A common spline is the natural cubic spline. A cubic spline has degree 3 with continuity $(0, 1, 2, 2, 3)$, i.e. the values and first and second derivatives are continuous. Natural means that the second derivatives of the spline polynomials are zero at the endpoints of the interval of interpolation.

$$S(a) \, = S(b) = 0.$$

Thus, the graph of the spline is a straight line outside of the interval, but still smooth.

Algorithm for computing natural cubic splines
Cubic splines are of the form $$S_j(x) = a_j + b_j(x - x_j) +  c_j(x-x_j)^2 + d_j(x-x_j)^3.$$

Given set of coordinates $$C = \bigl[ (x_0, y_0), (x_1, y_1), ..., (x_n, y_n) \bigr],$$ we wish to find set of $n$ splines $C^{2}$ for $Si(x)$.

These must satisfy:

$$\begin{align} S_i (x_i) &= y_i = S_{i-1} (x_i), && i = 1,\ \ldots,\ n-1, \\[4pt] S_{0} (x_0) &= y_0, \\[4pt] S_{n-1} (x_n) &= y_n ,\\[4pt] S'_i (x_i) &= S'_{i-1} (x_i), && i = 1,\ \ldots,\ n-1, \\[4pt] S_i (x_i) &= S_{i-1} (x_i), && i = 1,\ \ldots,\ n-1, \\[4pt] S_0 (x_0) &= S_{n-1} (x_n) = 0. \end{align}$$

Let us define one cubic spline $S$ as a 5-tuple $i = 0, …, n – 1$ where $a, b, c, d$ correspond to coefficients in the form shown earlier and $xt$ is equal to $xj$.

Algorithm for computing Natural Cubic Splines:

Input: set of coordinates $C$, with $(a, b, c, d, xt)$

Output: set splines which is composed of $n$ 5-tuples. \alpha_i = \frac{3}{h_i} (a_{i+1} - a_i) - \frac{3}{h_{i-1}} (a_i - a_{i-1}). $$ l_i &= 2 (x_{i+1} - x_{i-1}) - h_{i-1}\mu_{i-1}, \\ \mu_i &= \frac{h_i}{l_i}, \\ z_i &= \frac{\alpha_i - h_{i-1}z_{i-1}}{l_i}. \end{align}$$ c_j &= z_j - \mu_j c_{j+1}, \\[4pt] b_j &= \frac{a_{j+1} - a_j}{h_j} - \frac{h_j (c_{j+1} + 2c_j)}{3}, \\[4pt] d_j &= \frac{c_{j+1} - c_j}{3h_j}. \end{align}$$ S_{i,a} = a_i, \\ S_{i,b} = b_i, \\ S_{i,c} = c_i, \\ S_{i,d} = d_i, \\ S_{i,x} = x_i. \end{align}$$
 * 1) Create new array $a$ of size $|C| = n + 1$ and for $n + 1$ set $$a_i = y_i \,$$
 * 2) Create new arrays $b$ and $d$, each of size $n$.
 * 3) Create new array $h$ of size $n$ and for $i = 0, …, n$ set $$h_i = x_{i+1} - x_i \,$$
 * 4) Create new array $α$ of size $n$ and for $i = 0, …, n – 1$ set $$
 * 1) Create new arrays $c, l, μ, z$, each of size $i = 1, …, n – 1$.
 * 2) Set $$ l_0 = 1, {\mu}_0 = z_0 = 0 \,$$
 * 3) For $n + 1$ set the following:$$\begin{align}
 * 1) Set $$ l_n = 1; z_n = c_n = 0. \,$$
 * 2) For $i = 1, …, n – 1$, set the following:$$\begin{align}
 * 1) Create new set Splines and call it output_set.  Populate it with $n$ splines $S$.
 * 2) For $j = n – 1, n – 2, …, 0$ set the following: $$\begin{align}
 * 1) Output output_set

C++ implementation:

General expression for a C2 interpolating cubic spline
The general expression for the $n$th $i = 0, …, n – 1$ interpolating cubic spline at a point x with the natural condition can be found using the formula

$$S_i(x) = \frac{z_i(x - t_{i-1})^3}{6h_i} + \frac{z_{i-1}(t_i - x)^3}{6h_i} + \left[\frac{f(t_i)}{h_i} - \frac{z_ih_i}{6}\right](x - t_{i-1}) + \left[\frac{f(t_{i-1})}{h_i} - \frac{z_{i-1}h_i}{6}\right](t_i - x)$$

where
 * $$z_i = S_i''(t_i)$$ are the values of the second derivative at the $ti$th knot.
 * $$ h_i = t_i-t_{i-1} $$
 * $$ f(t_i^{}) $$ are the values of the function at the $n$th knot.

Representations and names
For a given interval $n + 1$ and a given extended knot vector on that interval, the splines of degree $a$ form a vector space. Briefly this means that adding any two splines of a given type produces spline of that given type, and multiplying a spline of a given type by any constant produces a spline of that given type. The dimension of the space containing all splines of a certain type can be counted from the extended knot vector:

$$\begin{align} a &= t_0 < \underbrace{t_1 = \cdots = t_1}_{j_1} < \cdots < \underbrace{t_{k-2} = \cdots = t_{k-2}}_{j_{k-2}} < t_{k-1} = b \\[4pt] j_i &\le n+1, \qquad i=1,\ldots,k-2. \end{align}$$ The dimension is equal to the sum of the degree plus the multiplicities
 * $$d = n + \sum_{i=1}^{k-2} j_i.$$

If a type of spline has additional linear conditions imposed upon it, then the resulting spline will lie in a subspace. The space of all natural cubic splines, for instance, is a subspace of the space of all cubic C2 splines.

The literature of splines is replete with names for special types of splines. These names have been associated with: Often a special name was chosen for a type of spline satisfying two or more of the main items above. For example, the Hermite spline is a spline that is expressed using Hermite polynomials to represent each of the individual polynomial pieces. These are most often used with $(n + 1)$; that is, as Cubic Hermite splines. In this degree they may additionally be chosen to be only tangent-continuous ($n + 1$); which implies that all interior knots are double. Several methods have been invented to fit such splines to given data points; that is, to make them into interpolating splines, and to do so by estimating plausible tangent values where each two polynomial pieces meet (giving us Cardinal splines, Catmull-Rom splines, and Kochanek-Bartels splines, depending on the method used).
 * The choices made for representing the spline, for example:
 * using basis functions for the entire spline (giving us the name B-splines)
 * using Bernstein polynomials as employed by Pierre Bézier to represent each polynomial piece (giving us the name Bézier splines)
 * The choices made in forming the extended knot vector, for example:
 * using single knots for $n + 2$ continuity and spacing these knots evenly on $n + 3$ (giving us uniform splines)
 * using knots with no restriction on spacing (giving us nonuniform splines)
 * Any special conditions imposed on the spline, for example:
 * enforcing zero second derivatives at $b$ and $i$ (giving us natural splines)
 * requiring that given data values be on the spline (giving us interpolating splines)

For each of the representations, some means of evaluation must be found so that values of the spline can be produced on demand. For those representations that express each individual polynomial piece $n &minus; 1$ in terms of some basis for the degree $i$ polynomials, this is conceptually straightforward: $$\sum_{j=0}^{k-2} c_j P_j(t).$$ However, the evaluation and summation steps are often combined in clever ways. For example, Bernstein polynomials are a basis for polynomials that can be evaluated in linear combinations efficiently using special recurrence relations. This is the essence of De Casteljau's algorithm, which features in Bézier curves and Bézier splines).
 * For a given value of the argument $i$, find the interval in which it lies $$t \in [t_i,t_{i+1}]$$
 * Look up the polynomial basis chosen for that interval $$P_0, \ldots, P_{k-2}$$
 * Find the value of each basis polynomial at $n$: $$P_0(t), \ldots, P_{k-2}(t)$$
 * Look up the coefficients of the linear combination of those basis polynomials that give the spline on that interval $n = 3$
 * Add up that linear combination of basis polynomial values to get the value of the spline at $a$:

For a representation that defines a spline as a linear combination of basis splines, however, something more sophisticated is needed. The de Boor algorithm is an efficient method for evaluating B-splines.