|
Notes for Thursday April 2 class -- Hermite and Bezier spline basis matrix
Describing a cubic spline segment with cubic polynomials
We showed in the previous lecture that we can use cubic spline segments,
laid end-to-end, to create smooth curves of arbitrary complexity.
Those spline curves can be used in various ways,
including the creation of geometric shapes and motion paths for animation.
There are various ways that a user might specify a cubic spline
segment.
One way is as an Hermite spline,
in which both the position and the tangent direction
at the beginning and end of each
cubic spline segment is specified.
Another way is as a Bezier spline,
in which two end positions and two intermediate guide points
for cubic spline segment is specified.
We show below that these methods are merely
different ways of specifying a value for each
coordinate as a cubic polynomial, which varies
as parameter t goes from 0 to 1:
x(t) = ax t3
+ bx t2
+ cx t
+ dx
y(t) = ay t3
+ by t2
+ cy t
+ dy
z(t) = az t3
+ bz t2
+ cz t
+ dz // Include this only if the curve is in 3D
From polynomial to dot product to matrix multiplication
We can think of a cubic polynomial as a dot product between a row vector
containing different powers of t and a column vector containing coefficients for each of those powers of t:
Describing a cubic polynomial in terms of those four
coefficients a,b,c,d makes it very easy for the computer
to evaluate a cubic spline, given any value of t.
But those coefficientsare very difficult for most users to work with.
Fortunately, once we have the polynomial in dot product form,
we can use matrix transformations to allow the user to describe
the cubic curve in ways that are easier for them to think about.
The general idea is that the user can pick four values A,B,C,D that
make sense to her. Then we use some 4x4 matrix to convert
from those four values to the raw polynomial coefficients a,b,c,d:
Below we show how to use matrix transformations
to go from an Hermite or Bezier description
of a cubic spline
to a description consisting of cubic polynomials.
In each case, we need to work out the correct
basis matrix for that particular way of
describing a cubic spline.
The Hermite basis matrix
Consider the positions P1 and P2 at the beginning and end of a cubic segment, respectively,
and the derivatives T1 and T2 at the beginning and end of a cubic segment, respectively.
We can think of P1,P2,T1 and T2 as each varying the weight of
a cubic function which affects only that one value, not the other three.
For example, the top function to the right affects the value of P1, but not P2,T1 or T2.
We can describe the sum of these four basis functions, weight respectively
by the values P1,P2,T1 and T2, as a multiplication of the column vector [P1,P2,T1,T2] by a 4x4 matrix:
|
←
|
2 | -2 | 1 | 1
| -3 | 3 | -2 | -1
| 0 | 0 | 1 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
The above 4x4 matrix is the Hermite basis matrix.
|
|
|
Hermite curves in multiple coordinates
Remember that everything we have just described is done independently for each coordinate.
So, for example, if we have a spline in 3D, we start with
two 3D positions
P1x,y,z and
P1x,y,z,
as well as
two 3D tangents
T1x,y,z and
T2x,y,z.
We need to multiply by the Hermite basis matrix
to get cubic polynomomial coefficients [a,b,c,d] in each of the three dimensions:
|
←
|
2 | -2 | 1 | 1
| -3 | 3 | -2 | -1
| 0 | 0 | 1 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
|
←
|
2 | -2 | 1 | 1
| -3 | 3 | -2 | -1
| 0 | 0 | 1 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
|
←
|
2 | -2 | 1 | 1
| -3 | 3 | -2 | -1
| 0 | 0 | 1 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
The three above multiplications
give us the coefficients needed for
three cubic polynomials, one in each dimension:
x(t) = ax t3
+ bx t2
+ cx t
+ dx
y(t) = ay t3
+ by t2
+ cy t
+ dy
z(t) = az t3
+ bz t2
+ cz t
+ dz
The Bezier basis matrix
The principle of Bezier interpolation
Suppose we start instead with the user view of end positions
A and D, with intermediate "steering" points B and C.
This produces the cubic curve which results from
three levels of linear interpolation, as shown
in the figure to the right.
The cubic curve (shown in
purple)
is the result of
varying t between 0 and 1 while
linearly interpolating
A→B and
B→C and
C→D (shown in
blue)
to produce three points,
followed by two more linear interpolations
between those points
to produce two points (shown in
green),
followed by a final linear interpolation
(shown in
red).
|
|
|
Defining the Bezier basis matrix
Mathematically, the three stages of linear interpolation
that we described above
looks like this:
(1-t) * ( (1-t) * ( (1-t) * A + t * B )
+ t * ( (1-t) * B + t * C ) )
+ t * ( (1-t) * ( (1-t) * B + t * C )
+ t * ( (1-t) * C + t * D ) )
If we multiply out the above expression to separate A,B,C and D, we get:
(1-t)3A + 3(1-t)2tB + 3(1-t)t2C + t3D
If we then multiply out the expressions of t within each term, we get:
(-t3 + 3t2 - 3t + 1) A + (3t3t - 6t2 + 3t) B + (-33 + 32) C + t3 D
We can describe the above polynomial as a matrix/vector multiplication,
where the four rows represent the weights a,b,c and d that we want to apply
to t3,t2,t and 1:
|
←
|
-1 | 3 | -3 | 1
| 3 | -6 | 3 | 0
| -3 | 3 | 0 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
The above 4x4 matrix is the Bezier basis matrix.
Bezier curves in multiple coordinates
As was true for the Hermite spline,
everything we have just described
for defining Bezier splines
is done independently for each coordinate.
So, for example, if we have a spline in 3D, we start with
four 3D positions
Ax,y,z,
Bx,y,z,
Cx,y,z,
and Dx,y,z.
We need to multiply by the Bezier basis matrix
to get cubic polynomomial coefficients [a,b,c,d] in each of the three dimensions:
|
←
|
-1 | 3 | -3 | 1
| 3 | -6 | 3 | 0
| -3 | 3 | 0 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
|
←
|
-1 | 3 | -3 | 1
| 3 | -6 | 3 | 0
| -3 | 3 | 0 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
|
←
|
-1 | 3 | -3 | 1
| 3 | -6 | 3 | 0
| -3 | 3 | 0 | 0
| 1 | 0 | 0 | 0
|
|
●
|
|
|
The three above multiplications
give us the coefficients needed for
three cubic polynomials, one in each dimension:
x(t) = ax t3
+ bx t2
+ cx t
+ dx
y(t) = ay t3
+ by t2
+ cy t
+ dy
z(t) = az t3
+ bz t2
+ cz t
+ dz
Homework
To give some students a chance to catch up,
I have decided not to give any homework assignment this week.
If you have fallen behind, please use this time
to finish and post any assignments that you have
yet to complete.
If you are already up to date with your work, feel free to add
features to your
last assignment, or to create another fun and interesting
and challenging scene for extra credit.
I have posted your midterm grades, which are based
on your cumulative work on the hw1 through hw5.
|
| |