Page 3: Cubics
CS559 Spring 2023 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)$ continuity. The common thing in computer graphics is to use cubic polynomial segments. That will allow us to get $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 $\mathbf{f_*}(t)$
for $t$ in some range. We construct this curve from a list of segments that are also curves: $\mathbf{f_0}(t)$
, $\mathbf{f_1}(t)$
, etc. Each of the segments applies to some portion of the “overall time”, so we could do something like:
$\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 $\mathbf{f_n}$ applies over the range $n\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 $0 \leq u < 1$
(or $\leq 1$
if appropriate), so:
$\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 $\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)$ continuity, we need to make sure $\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)$ continuity, we need to make sure that $\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 $t$): $$ \mathbf{f}(t) = \mathbf{a_0} + \mathbf{a_1} t + \mathbf{a_2} t^2 + \cdots + \mathbf{a_d} t^d $$
$$ \mathbf{f}(t) = \sum_{i=0}^d \mathbf{a_i} t^i $$
The $a_i$ are sometimes referred to as coefficients.
A few simple observations:
- If we have a polynomial of degree $d$ (that is, the highest power of the polynomial is $d$, so there is a $t^d$ term), we have $d+1$ coefficients.
- We can write the coefficients as a vector of length $d+1.$
- We can think of a quadratic (a degree 2 polynomial) as a cubic (a degree 3 polynomial) with its $a_3$ coefficient as 0.
- While the equation is non-linear in the parameter, it is linear in the coefficients. That is, for a given value of the parameter $t$, $\mathbf{f}(t)$ is a linear equation of the coefficients $a_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 $\mathbf{a} = (-6, 11, -6, 1)$, which gives us $\mathbf{f}(t) = t^3-6t^2+11t-6$ (we put $a_0$ first in the vector), we could also put it in the form $(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:
$$ \mathbf f(u) = \mathbf a_0 + \mathbf a_1 u + \mathbf a_2 u^2 + \mathbf a_3 u^3 $$
denoting the coefficients as $ \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):
$$ f_x(u) = a_{0x} + a_{1x} u + a_{2x} u^2 + a_{3x} u^3 $$
$$ f_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 ($f_x$ for the x-coordinate and $f_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 $ \mathbf a_0, \mathbf a_1, \mathbf a_2,$ and $\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=0$) and end (where $u=1$). Let’s call these points $\mathbf{p_0}$ and $\mathbf{p_1}$. If we write things in canonical form, the beginning is straightforward: $$\mathbf{p_0}=\mathbf{f}(0)=\mathbf{a_0}$$
The end is a bit more complicated. $$\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)$ for the cubic polynomial in the last section, you can compute it by plugging the number into the factored form $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=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.
Next: Interpolation and Hermite Cubics