If we look at cars from the 1970s and the 1990s, there’s really one big difference in their designs. The ones from the ’70s are boxy, and the ones from the ’90s are curvy. Since then, cars have become curvier and curvier and aesthetically so appealing!
While the gasoline prices in the United States were low in the 60s, in Europe, fuel was always more expensive. In 1962, Pierre Bézier, an engineer at Renault, and Paul de Casteljau, a mathematician at Citroen, independently developed Bezier curves for fitting smooth curves and surfaces, allowing streamlined bodies and increased fuel efficiency.
In this tutorial, we’ll try to understand the mathematics underlying piecewise polynomial interpolation and explore some cool things we can do with these objects.
2. Thinking About Polynomials as Points or Vectors
Polynomials are a basic means of approximation in all of science and mathematics. Let’s spend a moment reviewing our understanding of polynomials. A polynomial of degree is simply a function that takes real number as input and maps it to another real , where . However, polynomials in mathematics are special objects – they are vectors in the polynomial space .
Let’s unpack this a bit. When we imagine vectors, we’ll see geometric arrows from our undergraduate physics lessons. And that’s totally cool!
We know that, any geometric vector in -dimensional space can be written as a linear combination of the basis vectors , and . The addition of two vectors is defined component-wise and the result is also a vector. Scalar multiplication is defined component-wise as, .
Think about the collection of all polynomials of degree at most :
Polynomials in the set are isomorphic to geometric vectors in D-space. Any arbitrary degree polynomial can be expressed as a linear combination of the basis polynomials , and . These basis polynomials play the role of unit vectors:
Looking at it this way, the polynomial can be decomposed into three components: , and . From high-school math, we realize that, polynomials are also added component-wise.
What points or vectors are to D-space, polynomials are to the polynomial space :
We can choose different basis vectors for -dimensional space. The vectors , and are also basis vectors for -space. Pick any vector, such as . It can be expressed as a linear combination of the new basis vectors:
This powerful idea also carries over to the set of polynomials .
, and are another set of basis polynomials for . Now, if we pick an arbitrary polynomial, such as , it can be expressed as a linear combination, as follows:
3. The Case for Piecewise Polynomial Interpolation
Let’s review the problem of polynomial interpolation. We have an unknown underlying function or sometimes an expensive function . The values of the function are unknown on the interval , except for a finite subset of data-points:
We’re interested to approximate the unknown or expensive function , by a polynomial .
From analytic geometry, we know that two points determine a straight line, and three points uniquely determine a parabolic curve of degree . In general, there is a unique interpolating polynomial of degree that passes through data points.
In contrast, in piecewise polynomial interpolation, we construct a piecewise function consisting of multiple segments. The th segment, interpolates between the points and using the polynomial .
3.1. Runge Phenomenon
Consider the approximation of the function on determined by interpolation on the equidistant grid with points:
The graph of the degree- polynomial obtained from the equidistant grid – unlike the graph of , swings wildly between the grid points. The error from interpolation is large, especially near the endpoints, while near the center , it is fairly small. Such behavior is typical of equidistant interpolation. This is called the Runge phenomenon:
With piecewise polynomials, there is no need to fear equidistant data.
4. Bernstein Polynomials and Bézier Curves
Bézier curves are omniscient in computer graphics and computational geometry. A brief background of how these curves are built follows:
Consider a space-shuttle, that travels in a straight-line from a point to in time second. Let’s compute the position of the space-craft at an arbitrary time . The point divides the straight-line in the proportion , . By the section formula, the coordinates of the point are given by:
This is the parametric equation of the motion of the space-craft. The points and control what the straight-line path looks like, so they are called control points.
Assume that, we have points , and . Imagine a blue particle moving from towards on a straight-line, a green particle moving from towards . Suppose, a third red particle moves along the straight-line joining blue and green particles:
How might we compute the trajectory of the red particle? By a double-application of the section formula, we have:
But, we saw earlier, that , and are like unit vectors. All quadratic curves can be generated by choosing different linear combinations of , and . Thus, the points , and control what the parabolic curve looks like.
The basis polynomials:
are called Bernstein basis polynomials. The quadratic curve corresponding to the control points , , is called the quadratic Bezier curve and is given by:
The quadratic Bezier curve interpolates between the points and , whereas is an off-curve point.
Computer graphics(CG) aficionados reserve the term control point for an off-curve point such as and refer to the on-curve points, as anchor points. In CG editors such as Adobe Illustrator, not all control points are known in advance. The shape of the quadratic curve is controlled by moving around the control points using the Pen tool (Bezier tool) until the curve has the desired shape. Thus, using the Bernstein basis to represent degree polynomials is advantageous. Moving has a direct and intuitive effect on the curve.
When rendering a TrueType font or a car body design, a smooth curve or surface is constructed, by chaining together several Bezier curves or patches.
5. Hermite Basis Polynomials and Cubic Hermite Interpolation
Hermite interpolation allows us to express any cubic polynomial in terms of two data-points and and the tangent slopes at these two points.
We derive the equation of a Hermite polynomial, by analyzing the physical motion of a particle under certain constraints. Let us imagine a particle that traverses a path given by the parametric equation , where denotes time. The first derivative of this function is .
The position of the particle at times , and are known. The direction of motion of the particle at times , and are also known. We have:
In the matrix form, we can write:
In essence, we have managed to find the unique cubic curve determined by two data points and and the slopes at these points and .
6. Spline Functions
The most common piecewise polynomial interpolation uses spline functions. Mathematically, a spline of degree , on a grid:
of data-points, also called knots, chains together sub-curves. Each sub-curve interpolates between two successive knot-points. Each sub-curve is a degree- polynomial:
An additional requirement is that the whole spline of degree-, must be times differentiable, and further its derivatives must be continuous. We discuss the consequences of this requirement, at length, further ahead.
We could use straight lines and parabolas for the segments of a spline. However, a polyline has sharp corners, so linear splines are not differentiable at the knot points. A quadratic curve has a constant second derivative. If we use quadratic curves, the curviness of one segment near a knot would not match the curviness of the preceding one. So, the most popular choice for the segments of a spline is cubic curves.
6.1. Cubic Spline Interpolant
A cubic spline uses cubic polynomials of degree to interpolate between successive knots. A cubic spline interpolant satisfies the following conditions:
- Each piece or segment on the interval is a cubic polynomial.
- for each .
- , and .
Condition (3) is simply a translation of the requirement that the whole spline should be times differentiable and these derivatives must be continuous. As a crude approximation, we know that a continuous curve is one that can be drawn without lifting the pen from the paper. The individual segments of are cubic polynomials, so they are continuous themselves. The only consideration is the continuity at the knot points.
For the curve to be continuous at any given knot-point , whether we approach it from the left, or we approach it from the right, the spline function must approach , regardless. Suppose the left piece is and the right piece is . This motivates . A similar argument follows for the first and second derivatives because we would like those to be continuous.
6.2. Construction of the Cubic Spline
To construct the cubic spline interpolant on an interval that divided into subintervals, we require segments . In line with condition (1), the segment is a cubic polynomial of the form:
and has constants. Therefore, we have to determine the values of constants.
The first and second derivatives of are given by:
So, , and . Also, the quantity appears often, so we let . Applying conditions (2) and (3), we obtain:
for each . S0lving for in equation (4) and substituting this value in equations (2) and (3) gives, for each , the new equations:
The final relationship is obtained by solving equation (5) first for :
and then with a reduction of the index, for . This gives:
Substituting these values into the equation derived from (6), with the index reduced by one, gives the linear system of equations:
for each . This system involves only the as unknowns. The values of and are given respectively by the spacing of the knots and the values at the knot-points. Once the values of are determined, it is a simple task to find the remainder of the constants and from equations (4) and (6).
6.3. The Natural Cubic Spline
An open question that arises from the preceding discussion is, whether a solution for the system of linear equations involving the unknowns exists, and if so, is it unique?
If we add two natural boundary conditions:
then we get, and . This results in a nice tridiagonal system of equations , that can be solved using Gaussian elimination:
A quick numerical example should help crystallize these ideas. Suppose we’re given the data points , , and and to form a cubic spline to approximate the function . So, the matrix and the vectors and have the form:
The resulting cubic spline curve is given by:
6.4. A Comparison of Different Piecewise Polynomial Interpolation Methods
Each interpolation method has its pros and cons.
A natural cubic spline segment assumes the position, the first derivative, and the second derivative from the preceding segment. Thus, the whole curve as well as its first two derivatives are continuous. However, any change in any segment changes the whole curve. Thus, the control is not local.
A B-Spline curve does not have to interpolate any of its control points. Unlike natural splines and Bezier curves, each segment is a weighted sum of only basis functions, where is the degree of the curve, giving the points local control. Thus, to create a large model with continuity and local control, we pretty much want to use cubic B-Splines.
The differences between various piecewise techniques is summarized below:
Today, spline functions are extensively used in the Computer-Aided Design (CAD) software for rendering car body surfaces. Complex surfaces can be modeled far beyond hand techniques.
Bezier curves have found use in computer graphics and typography. Cubic Bezier curves are the native curve format in Adobe Postscript fonts. Because, these curves are specified mathematically, they are infinitely scalable.
As with Bezier curves, a Bezier surface is defined by a mesh of control points.
As a small application, here is a rendition of the Utah Teapot in pastel color using Bezier surfaces:
The Utah Teapot is an icon of the computer graphics industry. It was one of the first computer graphics objects to be modeled using Bezier curves. The control points and Bezier patches of the Utah Teapot are publicly available.
In this article, we learnt, a few elementary methods of piecewise interpolation. Quadratic Bezier curves are parametrized by two data-points and one control-point. Cubic Hermite curves are parametrized by two end-points and the tangent slopes at the end-points.
A spline function of degree on a grid of data points has segments, where each segment is a polynomial of degree , and its first derivatives are continuous. A natural cubic spline is a spline of degree , with the boundary condition that the spline is a straight-line near the first and last data points. It satisfies .