Page 3: Cubics

Spring 2025 Sample Solution

We will create complicated shapes by putting together simple pieces. We need to do this in a careful way, otherwise we won’t get continuity.

If we try to make shapes out of linear pieces (line segments), we can never do better than C(0)C(0) continuity. The common thing in computer graphics is to use cubic polynomial segments. That will allow us to get C(1)C(1) (or better) continuity, and also have a lot of flexibility in the shapes that we can create.

We could use even higher degree polynomials (quartic polynomials, quintic polynomials, etc.). However, for many reasons, in computer graphics, cubics are usually sufficient.

This material is covered in the book in Sections 15.3 through 15.5.

Piecewise Polynomials

We will be making our curves by breaking a big curve into a bunch of smaller segments, and representing each segment as a polynomial. Our curves are piecewise polynomials because each piece of them is a polynomial. Mathematicians use the term spline to refer to piecewise polynomials; however, this term sometime has other connotations.

Before considering the pieces, we should be clear about how they fit together. For the moment, denote the overall curve as f(t)\mathbf{f_*}(t) for tt in some range. We construct this curve from a list of segments that are also curves: f0(t)\mathbf{f_0}(t), f1(t)\mathbf{f_1}(t), etc. Each of the segments applies to some portion of the “overall time”, so we could do something like:

f(t)=if 0t<1 then f0(t)elif 1t<2 then f1(t)elif 2t<3 then f2(t)etc.\mathbf{f_*}(t) = \begin{aligned} \mathrm{if}\ & 0 \leq t < 1 \ \mathrm{then}\ \mathbf{f_0}(t) \\ \mathrm{elif}\ & 1 \leq t < 2 \ \mathrm{then}\ \mathbf{f_1}(t) \\ \mathrm{elif}\ & 2 \leq t < 3 \ \mathrm{then}\ \mathbf{f_2}(t) \\ \mathrm{etc.} \end{aligned}

for however many pieces we might have, with the slight caveat that we need to deal with closing the interval at the end (so fn\mathbf{f_n} applies over the range ntn+1n\leq t \leq n+1).

This is kind of inconvenient, since it means each segment must be defined in terms of where it goes in the overall time. It is much better (and more common) to define each segment as spanning over the range 0u<10 \leq u < 1 (or 1\leq 1 if appropriate), so:

f(t)=if 0t<1 then f0(t0)elif 1t<2 then f1(t1)elif 2t<3 then f2(t2)etc.\mathbf{f_*}(t) = \begin{aligned} \mathrm{if}\ & 0 \leq t < 1 \ \mathrm{then}\ \mathbf{f_0}(t-0) \\ \mathrm{elif}\ & 1 \leq t < 2 \ \mathrm{then}\ \mathbf{f_1}(t-1) \\ \mathrm{elif}\ & 2 \leq t < 3 \ \mathrm{then}\ \mathbf{f_2}(t-2) \\ \mathrm{etc.} \end{aligned}

Of course, we could choose to make the “break points” where we switch functions be other times, and shift and scale time accordingly so that each fi\mathbf{f_i} gets the appropriate range.

Since each of our pieces is going to be a polynomial, we know that within each piece we have continuity (for all derivatives). Therefore, we only need to be concerned about continuity at the place where the switch functions. If we want C(0)C(0) continuity, we need to make sure fi(1)=fi+1(0)\mathbf{f_i}(1)=\mathbf{f_{i+1}}(0) (the end of one piece equals the beginning of the next). If we want C(1)C(1) continuity, we need to make sure that fi(1)=fi+1(0)\mathbf{f_i'}(1)=\mathbf{f'_{i+1}}(0) (the first derivative at the end of one segment is equal to the first derivative at the beginning of the next).

Polynomials

A polynomial is a function of a single parameter (in this case tt):

f(t)=a0+a1t+a2t2++adtd\mathbf{f}(t) = \mathbf{a_0} + \mathbf{a_1} t + \mathbf{a_2} t^2 + \cdots + \mathbf{a_d} t^d
f(t)=i=0daiti\mathbf{f}(t) = \sum_{i=0}^d \mathbf{a_i} t^i

The aia_i are sometimes referred to as coefficients.

A few simple observations:

  1. If we have a polynomial of degree dd (that is, the highest power of the polynomial is dd, so there is a tdt^d term), we have d+1d+1 coefficients.
  2. We can write the coefficients as a vector of length d+1d+1.
  3. We can think of a quadratic (a degree 2 polynomial) as a cubic (a degree 3 polynomial) with its a3a_3 coefficient as 0.
  4. While the equation is non-linear in the parameter, it is linear in the coefficients. That is, for a given value of the parameter tt, f(t)\mathbf{f}(t) is a linear equation of the coefficients aia_i.

There are many different was to write a polynomial. The “coefficient form” above is just one way to write it. For example, if we have a cubic polynomial with the coefficient vector a=(6,11,6,1)\mathbf{a} = (-6, 11, -6, 1), which gives us f(t)=t36t2+11t6\mathbf{f}(t) = t^3-6t^2+11t-6 (we put a0a_0 first in the vector), we could also put it in the form (t1)(t2)(t3)(t-1)(t-2)(t-3).

This idea of having different forms of polynomials will be important. Ultimately, they are all the same polynomial, but some forms will be easier to work with than others.

Cubics

A cubic is a polynomial of degree 3.

We write a cubic polynomial (in coefficient or canonical form) as:

f(u)=a0+a1u+a2u2+a3u3\mathbf f(u) = \mathbf a_0 + \mathbf a_1 u + \mathbf a_2 u^2 + \mathbf a_3 u^3

denoting the coefficients as a0,a1,a2,a3 \mathbf a_0, \mathbf a_1, \mathbf a_2, \mathbf a_3 - in boldface since they are vectors. This is a nicer notation than writing (if our vectors are 2d):

fx(u)=a0x+a1xu+a2xu2+a3xu3f_x(u) = a_{0x} + a_{1x} u + a_{2x} u^2 + a_{3x} u^3 fy(u)=a0y+a1yu+a2yu2+a3yu3f_y(u) = a_{0y} + a_{1y} u + a_{2y} u^2 + a_{3y} u^3

It’s useful to remember that we have a separate function for each dimension (fxf_x for the x-coordinate and fyf_y for the y-coordinate).

Notice that a cubic segment has 4 coefficients. When we specify the cubic in some other way, we need to give enough information to compute these 4 things. If we give too little information or too much, it won’t work exactly. Therefore, other representations will use 4 numbers too.

Trying to control the cubic by specifying the coefficients is not easy (e.g., what values for a0,a1,a2, \mathbf a_0, \mathbf a_1, \mathbf a_2, and a3\mathbf a_3 give a desired shape?). Therefore, we almost always specify cubic curves using some other form.

If we want to connect cubics, we would like to specify the beginning (where u=0u=0) and end (where u=1u=1). Let’s call these points p0\mathbf{p_0} and p1\mathbf{p_1}. If we write things in canonical form, the beginning is straightforward:

p0=f(0)=a0\mathbf{p_0}=\mathbf{f}(0)=\mathbf{a_0}

The end is a bit more complicated.

p1=f(1)=a0+a1+a2+a3\mathbf{p_1}=\mathbf{f}(1)=\mathbf{a_0}+\mathbf{a_1}+\mathbf{a_2}+\mathbf{a_3}

The problem is that we have lots of choices, and this doesn’t say what happens in between the end points.

The solution will be to use different forms for the cubics. We’ll specify values that are convenient, and compute the coefficients from these. Although, we can think of these different representations and simply use the polynomials in these other forms. As an analogy, if I ask you to compute f(3)f(3) for the cubic polynomial in the last section, you can compute it by plugging the number into the factored form f(t)=(t1)(t2)(t3)f(t)=(t-1)(t-2)(t-3) without figuring out what the coefficients are.

On the next page, we’ll learn about a particularly useful form for cubics. But first, a quick question to make sure you are reading.

A Cubic Question

To check that you are understanding things, answer this question:

We would like to make a cubic curve that starts (u=0u=0) at the point 10,5 and ends at the point 50,75. Assume we write the cubic in the canonical form. Give values of the coefficients that satisfy the endpoints (there are many correct answers - give any one). Put your answers into 05-03-01.txt.

Box 05-03-01   05-03-01.txt
There are no points associated with Box 05-03-01.
Next: Interpolation and Hermite Cubics