Polynomial Pieces

The most popular representations for curves in computer graphics are piecewise functions where each curve piece is represented by a polynomial. Piecewise linear representations (a line segment is a polynomial of order 1) are a special case of this. In this section, we look over the mathematics of the individual polynomial pieces. In the next section, we discuss how to put pieces of polynomials together.

This page is adapted from old course notes. A chapter of Fundamentals of Computer Graphics was also derived from the same notes.

Polynomials are functions of the form:

f(t)=a0+a1t+a2t2++antn, f(t) = a_0 + a_1 t + a_2 t^2 + \ldots + a_n t^n,
(1)
where the aia_i are the coefficients. The number of coefficients n+1n+1 is called the order. Notice that the order is one more than the highest power of tt in the expression, since we have a coefficient for n=0.n=0. If we write the coefficients of the polynomial as a vector (of length n+1n+1), we can write Equation Equation 1 as:
f(t)=i=0naiti. \mathbf{f}(t) = \sum_{i=0}^n \mathbf{a_i} t^i.
(2)
We refer to this form of writing a polynomial (e.g. as coefficients multiplied by the various powers of the parameter) as the canonical form.

The degree of a polynomial is the highest power of the parameter. A polynomial of order 4 may be of degree 3, but it may be of a lower degree if an=0.a_n = 0.

We can generalize the canonical form of Equation Equation 2 as:

f(t)=i=0ncibi(t), \mathbf{f}(t) = \sum_{i=0}^n \mathbf{c_i} b_i(t),
(3)
where c\mathbf{c} is a vector of n+1n+1 coefficients, and each bi(t)b_i(t) is a polynomial. The set of n+1n+1 polynomials bi(t)b_i(t) are called basis functions, or blending functions. Notice that Equation Equation 2 is simply Equation Equation 3 with bi(t)=ti.b_i(t) = t^i. If the set of basis function is chosen correctly, any polynomial of order n+1n+1 can be represented by an appropriate choice of c.\mathbf{c}.

While canonical form is sufficient for describing any polynomial, the coefficients are not necessarily convenient. Throughout this chapter, we will find sets of basis functions such that the coefficients are convenient ways to control the curves represented by the polynomial functions.

For specifying curves, we can either create a separate polynomial for each dimension of the curves’ embedding, or use a vector form of Equations like Equation Equation 3, where the coefficients are points. Note that even in such a case, the basis or blending functions still produce scalar values.

A Line Segment

To introduce the concepts of piecewise polynomial curve representations, we will discuss line segments. In practice, line segments are so simple that the mathematical derivations will seem excessive. However, by understanding this simple case, things will be easier when we move on to more complicated polynomials.

Consider a line segment that connects point p0\mathbf{p_0} to p1\mathbf{p_1}. We could write the parametric function over the unit domain for this line segment as:

f(u)=(1u)p0+up1 \mathbf{f}(u) = (1-u) \mathbf{p_0} + u \mathbf{p_1}
(4)
By writing this in vector form, we have hidden the dimensionality of the points, and the fact that we are dealing with each dimension separately. For example, were we working in 2D, we could have created separate equations:
fx(u)=(1u)p0x+up1xfy(u)=(1u)p0y+up1y, \begin{align} f_x(u) &= (1-u) {\mathbf{p}_{0x} + u {\mathbf{p}_{1x}} } \\ f_y(u) &= (1-u) {\mathbf{p}_{0y} + u {\mathbf{p}_{1y}} }, \end{align}
(5)
using the (admittedly ugly) notation p0x\mathbf{p}_{0x} to refer to the xx coordinate of point 0.

The line that we specify is determined by the two end points.

but from now on we’ll stick to vector notation since its cleaner. We will call the vector of control parameters p\mathbf{p} the control points, and each element of p\mathbf{p} a control point.

While describing a line segment by the positions of its endpoints is obvious and usually convenient, there are other ways to describe a line segment. For example:

  1. the position of the center of the line segment, the orientation, and the length;
  2. the position of one endpoint and the position of the second point relative to the first;
  3. the position of the middle of the line segment and one end.

It should be fairly obvious that given one kind of a description of a line segment, we can switch to another.

A different way to describe a line segment is using the canonical form of the polynomial (as discussed in Section Polynomial Notation),

f(u)=a0+ua1. \mathbf{f}(u) = \mathbf{a_0} + u \mathbf{a_1}.
(6)
Any line segment can be represented either by specifying a0\mathbf{a_0} and a1\mathbf{a_1}, or the endpoints (p0\mathbf{p_0} and p1\mathbf{p_1}). It is usually more convenient to specify the endpoints, because we can compute the other parameters from the endpoints.

To write the canonical form in as a vector expression, we define a vector u\mathbf{u} that is a vector of the powers of uu:

u=[1 u u2 u3  un] \mathbf{u} = \left[ 1\ u\ u^2\ u^3\ \ldots\ u^n \right]
(7)
so that Equation Equation 2 can be written as:
f(u)=u a. \mathbf{f}(u) = \mathbf{u}\ \mathbf{a}.
(8)
This vector notation will make transforming between different forms of the curves easier.

Equation Equation 8 describe a curve segment by the set of polynomial coefficients for the simple form of the polynomial. We call such a representation the canonical form. I will denote the parameters of the canonical form by a\mathbf{a}.

While it is mathematically simple, canonical form is not always the most convenient way to specify curves. For example, we might prefer to specify a line segment by the positions of its endpoints. If we want to define p0\mathbf{p_0} to be the beginning of the segment (where the segment is when u=0u=0) and p1\mathbf{p_1} to be the end of the line segment (where the line segment is at u=1u=1), we can write:

p0=f(0)=[1 0][a0 a1]p1=f(1)=[1 1][a0 a1]. \begin{array}{llll} \mathbf{p_0} &= \mathbf{f}(0) &= \left[1\ 0\right] & \left[ \mathbf{a_0}\ \mathbf{a_1}\right]\\ \mathbf{p_1} &= \mathbf{f}(1) &= \left[1\ 1\right] & \left[ \mathbf{a_0}\ \mathbf{a_1}\right]. \end{array}
(9)
We can solve these equations for a0\mathbf{a_0} and a1\mathbf{a_1}:
a0=p0a1=p1p0. \begin{align} \mathbf{a_0} &= \mathbf{p_0}\\ \mathbf{a_1} &= \mathbf{p_1} - \mathbf{p_0}. \end{align}
(10)

Matrix Form for Polynomials

While this first example was easy easy enough to solve, for more complicated examples it will be easier to write Equation Equation 9 in the form:

[p0p1]=[1011][a0a1]. \left[ \begin{array}{c} \mathbf{p_0} \\ \mathbf{p_1} \end{array} \right] = \left[ \begin{array}{cc} 1 & 0 \\ 1 & 1 \end{array} \right] \left[ \begin{array}{c} \mathbf{a_0} \\ \mathbf{a_1} \end{array} \right].
(11)
Or, if we call this constraint matrix C,\mathbf{C}, we can write
p=C a, \mathbf{p} = \mathbf{C}\ \mathbf{a},
(12)
although, this is being a little sloppy with notation.1 If having vectors of points bothers you, you can consider each dimension independently (so that p\mathbf{p} is [p0x p1x][{p_0}_x\ {p_1}_x] or [p0y p1y][{p_0}_y\ {p_1}_y]) and a\mathbf{a} is handled correspondingly).

We can solve Equation Equation 12 for a\mathbf{a} by finding the inverse of C.\mathbf{C}. This matrix we will call the basis matrix, and we will denote it by B.\mathbf{B}. The basis matrix is very handy since it tells us how to convert between the convenient parameters p\mathbf{p} and the canonical form a,\mathbf{a_,} and therefore gives us an easy way to evaluate the curve:

f(u)=u B p. \mathbf{f}(u) = \mathbf{u}\ \mathbf{B}\ \mathbf{p}.
(13)
We can find a basis matrix for whatever form of the curves that we want, providing that there are no non-linearities in the definition of the parameters.

Another Example: Suppose we want to parameterize the line segment so that p0\mathbf{p_0} is the half-way point (u=.5u=.5), and p1\mathbf{p_1} is the ending point (u=1u=1). To derive the basis matrix for this parameterization:

(p0)=f(.5)=1 a0+.5 a1(p1)=f(1)=1 a0+1 a1 \begin{align} \mathbf(p_0) &= \mathbf{f}(.5) = 1\ \mathbf{a_0} + .5\ \mathbf{a_1} \\ \mathbf(p_1) &= \mathbf{f}(1) = 1\ \mathbf{a_0} + 1\ \mathbf{a_1} \end{align}
(14)
So
C=[1.511] \mathbf{C} = \left[ \begin{array}{rr} 1 & .5 \\ 1 & 1 \end{array} \right]
(15)
and, therefore
B=C1=[2122]. \mathbf{B} = \mathbf{C}^{-1} = \left[ \begin{array}{rr} 2 & -1 \\ -2 & 2 \end{array} \right].
(16)

Beyond Line Segments

Line segments are simple enough that the effort of finding a basis matrix is silly. However, it was good practice for curves of higher degree. First, let’s consider quadratics (curves of degree 2). The advantage of the canonical form (Equation Equation 2) is that it works for these more complicated curves, just by letting nn be a larger number.

A quadratic (a degree 2 polynomial) has 3 coefficients (it has order 3), a0\mathbf{a_0}, a1\mathbf{a_1}, and a2\mathbf{a_2}. These coefficients are not convenient for describing the shape of the curve. However, we can use the same basis matrix method to devise more convenient parameters. If we know the value of u,u, Equation Equation 2 becomes a linear equation in the parameters,and the linear algebra from the last section still works.

Suppose that we wanted to describe our curves by the position of the beginning (u=0u=0), middle2 (u=.5u=.5), and end (u=1u=1). Filling the appropriate values into Equation Equation 2:

p0=f(0)= a0+ 01a1+ 02a2p1=f(.5)= a0+ .51a1+ .52a2p2=f(1)= a0+ 11a1+ 12a2. \begin{array}{llllll} \mathbf{p_0} & = f(0) & = \ \mathbf{a_0} + \ 0^1 & \mathbf{a_1} & +\ 0^2 & \mathbf{a_2}\\ \mathbf{p_1} & = f(.5) & = \ \mathbf{a_0} + \ .5^1 & \mathbf{a_1} & +\ .5^2 & \mathbf{a_2}\\ \mathbf{p_2} & = f(1) & = \ \mathbf{a_0} + \ 1^1 & \mathbf{a_1} & +\ 1^2 & \mathbf{a_2}. \end{array}
(17)
So the constraint matrix is:
C=[1001.5.25111], \mathbf{C} = \left[ \begin{array}{ccc} 1 & 0 & 0 \\ 1 & .5 & .25 \\ 1 & 1 & 1 \end{array} \right],
(18)
and the basis matrix is:
B=C1=[100341242] \mathbf{B} = \mathbf{C}^{-1} = \left[ \begin{array}{ccc} 1 & 0 & 0 \\ -3 & 4 & -1 \\ 2 & -4 & 2 \end{array} \right]
(19)

There is one additional type of constraint (or parameter) that is sometimes convenient to specify: the derivative of the curve (with respect to its free parameter) at a particular value. Intuitively, the derivatives tell us how the curve is changing, so that the first derivative tells us what direction the curve is going, the second derivative tells us how quickly the curve is changing direction, etc. We will see examples of why it is useful to specify derivatives later.

For the quadratic,

f(u)=a0+a1u+a2u2, \mathbf{f}(u) = \mathbf{a_0} + \mathbf{a_1} u + \mathbf{a_2} u^2,
(20)
the derivatives are simple:
f(u)=dfdu=a1+2a2u, \mathbf{f}'(u) = \frac{df}{du} = \mathbf{a_1} + 2 \mathbf{a_2} u,
(21)
and
f(u)=d2fdu2=dfdu=2a2. \mathbf{f}''(u) = \frac{d^2f}{du^2} = \frac{d f'}{du} = 2 \mathbf{a_2}.
(22)
Or, more generally,
f(u)=i=1niui1ai,f(u)=i=2ni(i1)ui2ai. \begin{align} \mathbf{f'}(u) &= \sum_{i=1}^n i u^{i-1} \mathbf{a_i}, \\ \mathbf{f''}(u) &= \sum_{i=2}^n i (i-1) u^{i-2} \mathbf{a_i}. \end{align}
(23)

For example, consider a case where we want to specify a quadratic curve segment by the position, first, and second derivative at its middle (u=.5u=.5).

p0=f(.5)= a0+.51a1+.52a2p1=f(.5)=a1+2(.5)a2p2=f(.5)=2a2. \begin{array}{lllllrrl} \mathbf{p_0}& = f(.5) &=\ \mathbf{a_0} +&.5^1 & \mathbf{a_1} + & & .5^2&\mathbf{a_2}\\ \mathbf{p_1}& = f'(.5) &= & & \mathbf{a_1} + & 2& (.5)&\mathbf{a_2}\\ \mathbf{p_2}& = f''(.5)&= & & & 2& &\mathbf{a_2}. \end{array}
(24)
So the constraint matrix is:
C=[1.5.25011002], \mathbf{C} = \left[ \begin{array}{rrr} 1 & .5 & .25 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{array} \right],
(25)
and the basis matrix is:
B=C1=[1.5.12501.500.5] \mathbf{B} = \mathbf{C}^{-1} = \left[ \begin{array}{rrr} 1 & -.5 & .125 \\ 0 & 1 & -.5 \\ 0 & 0 & .5 \end{array} \right]
(26)

Basis Matrices for Cubics

Cubic polynomials are popular in graphics (See Section Cubics). One reason is that the basis matrix is a 4x44x4 matrix, which is something graphics people work with a lot. The derivations for the various forms of cubics are just like the derivations we’ve seen already in this section. We will work through one more example, for practice.

A very useful form of a cubic polynomial is the Hermite form, where we specify the position and 1st derivative at the beginning and end. That is,

p0 =f(0)=a0 +01 a1+02 a2+03 a3p1 =f(0)= a1+201 a2+302 a3p2 =f(1)=a0 +11 a1+12 a2+13 a3p3 =f(1)= a1+211 a2+312 a3 \begin{array}{lllrllrl} \mathbf{p_0}\ =&f(0) &= \mathbf{a_0}\ +&0^1 \ \mathbf{a_1} & + &0^2\ \mathbf{a_2}+ & & 0^3\ \mathbf{a_3}\\ \mathbf{p_1}\ =&f'(0)&= & \ \mathbf{a_1} & + 2&0^1\ \mathbf{a_2}+ & 3& 0^2\ \mathbf{a_3}\\ \mathbf{p_2}\ =&f(1) &= \mathbf{a_0}\ +&1^1 \ \mathbf{a_1} & + &1^2\ \mathbf{a_2}+ & & 1^3\ \mathbf{a_3}\\ \mathbf{p_3}\ =&f'(1)&= & \ \mathbf{a_1} & + 2&1^1\ \mathbf{a_2}+ & 3& 1^2\ \mathbf{a_3} \end{array}
(27)
So the constraint matrix is:
C=[1000010011110123], \mathbf{C} = \left[ \begin{array}{rrrr} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 \\ 0 & 1 & 2 & 3 \end{array} \right],
(28)
and the basis matrix is:
B=C1=[1000010032312121] \mathbf{B} = \mathbf{C}^{-1} = \left[ \begin{array}{rrrr} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ -3&-2 & 3 & -1\\ 2 & 1 & -2& 1 \end{array} \right]
(29)
We will discuss Hermite cubic splines in Section Hermite.

Blending Functions

If we know the basis matrix (B\mathbf{B}) we can multiply it by the parameter vector (u\mathbf{u}) to get a vector of functions

b(u)=u B. \mathbf{b}(u) = \mathbf{u}\ \mathbf{B}.
(30)
Notice that we denote this vector by b(u)\mathbf{b}(u) to emphasize the fact that its value depends on the free parameter u.u. We call the elements of b(u)\mathbf{b}(u) the blending functions because they specify how to blend the values of the parameter vector together:
f(u)=i=0nbi(u)pi. \mathbf{f}(u) = \sum_{i=0}^n \mathbf{b_i}(u) \mathbf{p_i}.
(31)
It is important to note that for a chosen value of uu, Equation Equation 31 is a linear equation, specifying a linear blend (or weighted average) of the control points. This is true no matter what degree polynomials are “hidden” inside of the bi\mathbf{b_i} functions.

Blending functions provide a nice abstraction for describing curves. Any type of curve that can be represented as a weighted linear combination of its control points, where those weights are computed as some arbitrary functions of the free parameter.

Another common term for blending function is basis function.

Interpolating Polynomials

In general, a polynomial of order mm can interpolate a set of mm values. If we are given a vector p\mathbf{p} of values to interpolate, and a corresponding vector t\mathbf{t} of sites, we can use the methods described in the previous sections to determine an mm by mm basis matrix, that would give us a function f(t)f(t) such that f(ti)=pi.f(t_i) = p_i. For any given vector t\mathbf{t} we would need to set up and solve an mm by mm linear system. This would provide us with a set of mm basis functions that would perform interpolation so the interpolating function is:

f(t)=i=0npibi(t). f(t) = \sum_{i=0}^n p_i b_i(t).
(32)
This requires that each element of t\mathbf{t} is distinct, since the curve can’t interpolate multiple values at a single site.

These interpolating basis functions can be derived in other ways. One particularly elegant way to define them is the Lagrange Form.

bi=j=0,jinxtjtitj. b_i = \prod^n_{j=0,j\neq i} \frac{x-t_j}{t_i-t_j}.
(33)
There are more computationally efficient ways to express the interpolating basis functions than the Lagrange Form. See (Source: deboor-splines-book) for details.

Interpolating polynomials provide a mechanism for defining curves that interpolate a set of points. Figure Figure (See below) shows some examples. While it is possible to create a single polynomial to interpolate any number of points, we rarely use high order polynomials to represent curves in computer graphics. Instead, interpolating splines (piecewise polynomial functions) are preferred. Some reasons for this are considered in Section Cardinal.

Figure

Figure 1:

Interpolating polynomials through multiple points. Notice the extra wiggles and overshooting between points. In Figure (See below), the 6th point is added completely changing the shape of the curve due to the non-local nature of interpolating polynomials.
Figure

Figure 2:

Interpolating Polynomial through 6 points
Figure

Figure 3:

Interpolating Polynomial through 5 and 6 points

Exercises

For each of the following, find the constraint matrix, the basis matrix, and the blending functions. You should not invert matrices by hand - use a program such as MATLAB or OCTAVE (a free MATLAB-like system).

  1. A Line Segment: Parameterized with p0\mathbf{p_0} being 25% of the way along the segment (u=.25u=.25), and p1\mathbf{p_1} being 75% of the way.
  2. A Quadratic: Parameterized with p0\mathbf{p_0} being the position of the beginning point (u=0u=0), p1\mathbf{p_1} being the 1st derivative at the beginning point, and p2\mathbf{p_2} being the 2nd derivative at the beginning point.
  3. A Cubic: With its control points being positions that are equally spaced (p0\mathbf{p_0} has u=0,u=0, p1\mathbf{p_1} has u=1/3u=1/3, p2\mathbf{p_2} has u=2/3u=2/3, and p3\mathbf{p_3} has u=1u=1).
  4. A Quintic: (a degree 5 polynomial, so the matrices will be 6x66x6) Where p0\mathbf{p_0} is the beginning position, p1\mathbf{p_1} is the beginning derivative, p2\mathbf{p_2} is the middle (u=.5u=.5) position, p3\mathbf{p_3} is the 1st derivative at the middle, p4\mathbf{p_4} is the position at the end, and p5\mathbf{p_5} is the 1st derivative at the end.
  5. Lagrange Polynomials: The Lagrange Form (Equation Equation 33) can be used to represent the interpolating cubic of Excursive 3. Use it at several different parameter values to confirm that it does produce the same results as the basis functions derived in Excursive 3.

  1. I am being very sloppy about whether vectors are row vectors or column vectors. In general, the sense of a vector should be obvious from its context, and I’ll skip all of the transpose symbols for vectors. ↩︎

  2. Notice that this is the middle of the parameter space, which might not be the middle of the curve itself. ↩︎