Curves and surfaces Consider a simple curve like the following

Curves and surfaces
Consider a simple curve like the following, which was drawn
freely.
It can be approximated to any degree of accuracy using straight
line segments. Of course, for very high accuracy, we need very
many straight line segments.
This is an example of a piecewise linear approximation to the
curve.
It is also possible to make either global or local polynomial
approximations to a curve. In fact, given n points, it is possible to exactly fit an n − 1 order polynomial. An approximate
polynomial of lower order may also be fitted.
1
Of course, OpenGL must eventually construct a curve from line
segments, but a curve or curved surface may be a more natural
representation from a modelling point of view.
Polynomial approximations to curves are particularly useful.
There are two possible ways of modeling a curve with polynomials:
• A single polynomial which approximates the full curve by
interpolating or approximating all the points
• A set of polynomials each interpolating or approximating a
number of the points, in a piecewise manner
The previous figure showed a linear piecewise approximation to
the function.
In general, if the number of points is even moderately large, a
single polynomial will be of a high order, and introduce spurious
“wiggles” in the approximating function.
Using a piecewise polynomial approximation, lower order polynomials can be used, and the curve typically looks “smoother.”
2
The following shows an example of a set of points fitted with
a high order polynomial and a piecewise linear polynomial of
order 2:
6th order polynomial, continuous
2nd order polynomials, piecewise
3
Representation
How should these curves be represented? There are are three
possible forms:
1. Express the y (and possibly also z) coordinate explicitly in
terms of x. For example,
y = 4x5 − 7x2 − 16
However, this most familiar approach has significant disadvantages:
• The curve cannot take on multiple y−values for the
same x−value.
• Vertical tangents cannot be represented.
2. Model curves as solutions to implicit equations. For example, the implicit equation for the unit circle is f (x, y) =
x2 + y 2 − 1 = 0. This form is good for when you need to
know if a given point is on the curve (or if not, on which
side of the curve is it). However, it does not give us an
analytic way of determining which points are on the curve.
4
3. Model curves as a set of parametric equations—one each for
x, y, and z. Each equation is in terms of the parameter,
t. Typically, the curve begins at t = 0 and ends at t = 1.
For example, the following two parametric equations define
the plot shown below for t in the range [0, 1].
x(t) = (t − 0.5)2
y(t) = (t − 1)2
1
0.8
0.6
0.4
0.2
0
0
0.05
0.1
0.15
5
0.2
0.25
The parametric form can represent curves with vertical tangents.
It also gives us a natural way of stepping along a curve. We will
represent segments of arbitrary curves as parametric polynomials.
Parametric cubic curves
What order of polynomials should we use? As we saw, higherorder polynomials can introduce unwanted “wiggles”. They
are also costly to evaluate. On the other hand, very low-order
polynomials (lines and quadratics) offer too little flexibility in
controlling the shape of curves. Cubic polynomials offer the
right balance.
6
We will represent the three parametric cubic polynomials as a
row vector called Q(t).
Q(t) = [x(t) y(t) z(t)]
where 0 ≤ t ≤ 1. These polynomials have the following form.
x(t) = axt3 + bxt2 + cxt + dx
y(t) = ay t3 + by t2 + cy t + dy
z(t) = az t3 + bz t2 + cz t + dz
The coefficients will have to be chosen somehow to model a
particular curve. We use matrix notation so that we can manipulate all 12 coefficients together.

3
2
Q(t) = t t t 1 ·












ax ay az
bx by bz
cx cy cz
dx dy dz













Defining T as the vector T = [t3 t2 t 1], the parametric equations can be rewritten as:
Q(t) = [x(t) y(t) z(t)] = T · C
where C is the coefficient matrix.
7
Without loss of generality, the parameter t can be restricted to
the interval [0, 1].
We will need to talk about the derivatives of Q(t). This is
because we have to model both the ability of the curve to pass
through particular points in space, and also to have a particular
shape.
The first derivative of Q(t) is as follows,
d
Q(t) = Q0(t)
dt
d
=
[T · C]
dt
= [3t2 2t 1 0] · C
=
2
2
2
3axt + 2bxt + cx 3ay t + 2by t + cy 3az t + 2bz t + cz
8
Types of continuity
If two curve segments joined at a point (called a knot) have the
same value for their first derivatives, they are said to be C1
continuous. If their first n derivatives have the same value
at a knot, the two curve segments are Cn continuous.
If two curve segments joined at a knot have first derivatives with
the same direction, but different magnitudes, they are said to
be G1 continuous; C n ⇒ Gn, but not conversely.
If two curve segments are merely joined at a knot, they are said
to be G0 continuous. (The G refers to “geometry.”)
Although G1 continuity is not as strong a constraint as C 1 continuity, both types of constraints produce curves which appear
smooth.
9
Constraints
The coefficients of a curve segment Q(t) are defined by constraints
on such parameters as the end points, tangent vectors, continuity at knots, etc. A constraint describes what is known. In
the simplest case, a constraint will be the location of an end
point or the tangent vector at an end point. That is, the curve
is constrained to go through the point; or have the specified tangent vector.
Cubic polynomials have four coefficients, so four constraints are
required.
10
The constraints can be made explicit by rewriting the coefficient
matrix C as C = M · G where G is a 4x3 matrix of geometric
constraints called the geometry matrix.
G and M are constant matrices, and
Q(t) = x(t) y(t) z(t)

3
2
= t t t 1 ·












=T ·M ·G
m11 m12 m13 m14
m21 m22 m23 m24
m31 m32 m33 m24
m41 m42 m43 m44


























·
g1x g1y g1z
g2x g2y g2z
g3x g3y g3z
g4x g4y g4z













Looking at only the x component, x(t) = T · M · Gx,
x(t) = (t3m11 + t2m21 + tm31 + m41)g1x +
(t3m12 + t2m22 + tm32 + m42)g2x +
(t3m13 + t2m23 + tm33 + m43)g3x +
(t3m14 + t2m24 + tm34 + m44)g4x
The y and z components are obtained similarly.
This is a weighted sum of the components of the geometry matrix, where the weights are the cubic polynomials in brackets.
These polynomials are called blending functions. They are
given by B = T · M .
11
This is quite similar to linear interpolation.
x(t) = (1 − t)g1x + tg2x
y(t) = (1 − t)g1y + tg2y
Here the geometry matrix consists of the two points (g1x, g1y )
and (g2x, g2y ), and the blending functions are (1 − t) and t.
The matrices G and M specify the geometric constraints and
the blending functions, (also called basis polynomials) respectively.
There are many possible forms for the basis polynomials.
We will now see how to determine the basis matrix, M , for
various parametric cubic curves.
Hermite curves
The first parametric cubic curve we will look at is the Hermite
curve.
The Hermite form of the cubic polynomial is specified by the
two endpoints (P1 and P4) and their tangents (R1 and R4).
To find the Hermite basis matrix MH , we can solve the 4 equations relating the four constraints to the polynomial coefficients.
12
For the x component only, the Hermite geometry vector is

G Hx =












P1x
P





4x 




1x 


R
R4x
and
x(t) = T · MH · GHx
3 2
= t t t 1 · M H · G Hx
so, substituting for the constraints (t = 0 and t = 1) directly,
P1x = x(0) = [0 0 0 1] · MH · GHx
P4x = x(1) = [1 1 1 1] · MH · GHx
Differentiating the expression for x(t) gives
x0(t) = 3t2 2t 1 0 · MH · GHx
h
i
we can now incorporate our two other constraints
R1x = x0(0) = [0 0 1 0] · MH · GHx
R4x = x0(1) = [3 2 1 0] · MH · GHx
Similar results are obvious for the y and z components.
We can combine the four constraint equations above into one
matrix...
13













P1
P4
R1
R4


























= G Hx =
x

0 0 0 1 

1 1 1 1 


0 0 1 0 
3 2 1 0
· M H · G Hx

For this to be true, MH must be the inverse of the constraint
matrix, so

MH =












−1

0 0 0 1 

1 1 1 1 
0 0 1 0
3 2 1 0






=












2 −2
1

1 

−3
3 −2 −1 
0
0
1
0
1
0
0
0






Our original function was Q(t) = T · M · G. Recalling that
the blending functions are given by B = T · M , the Hermite
blending functions are given by BH = T · MH . We express the
Hermite curve in its final form as the combination of blending
functions, weighted by the rows of the geometry matrix.
Q(t) = BH · GH = T · MH · GH
= (2t3 − 3t2 + 1)P1 + (−2t3 + 3t2)P4 +
(t3 − 2t2 + t)R1 + (t3 − t2)R4
14
Since Hermite curves are linear combinations of the elements of
the geometry matrix, they can be transformed by applying the
blending functions to the transformed geometry vector.
Therefore, the Hermite polynomials are invariant under translation, rotation, and scaling (but not perspective transformation.)
The following is a plot of the Hermite blending functions which
are multiplied by each of the geometry elements:
Hermite blending functions
1
HP4
HP1
0.8
0.6
0.4
HR1
0.2
0
HR4
−0.2
0
0.2
0.4
0.6
0.8
1
Note that the symmetry of these blending functions. At t = 0
the only blending function in effect is the one for P1. At t = 1
the only one in effect is the P4 blending function.
15
Bézier curves
The Hermite form of the cubic polynomial requires the derivatives at the endpoints. The Bézier form specifies the endpoint
vectors using two intermediate points (P2 and P3) which do not
lie on the curve.
The end point tangent vectors are defined as follows,
R1 = 3(P2 − P1),
R4 = 3(P4 − P3)
The Bézier geometry matrix GB is GB = [P1 P2 P3 P4]T
This can be written as a Hermite geometry matrix as follows:

GH =












P1
P4
R1
R4


























=
1 0
























0 0 
0 0
0 1
−3 3
0 0
0 0 −3 3
·
P1
P2
P3
P4













= MHB · GB
To find the Bézier basis matrix, MB , from the Hermite form,
Q(t) = T · MH · GH = T · MH · (MHB · GB )
= T · (MH · MHB ) · GB = T · MB · GB

So, MB = MH · MHB =













−1
3 −3 1 
3 −6
3 0
−3
3
0 0
1
0
0 0
16










Q(t) = T · MB · GB
= (1 − t)3P1 + 3t(1 − t)2P2 + 3t2(1 − t)P3 + t3P4
The four blending polynomials BB = T · MB are called the
Bernstein polynomials.
Cubic Bernstein polynomials
1
0.8
0.6
B1
B2
B4
B3
0.4
0.2
0
0.2
0.4
0.6
0.8
1
They have the property that they are non-negative and sum to
1 at any point in [0, 1]. So Q(t) is really a weighted average of
the control points. This has the consequence that the curve is
bounded by the four control points; the control points form a
convex hull for the curve segment. (This is useful for clipping
the curves.)
17
Joining curve segments
Both the Hermite and Bézier curves can be joined to form segments of a larger curve. For both types of curves we have four
control points, with the point specifying the end point of one
segment serving as the start point for the next segment.
For a curve composed of two joined Hermite curves, the control points are P1, P4, R1, R4 and P4, P7, R5, R7. To ensure G1
continuity we must have R5 = kR4, with k > 0. An example
is shown below,
P4
R1
R4
P1
R5
P7
R7
for C 1 continuity we must have k = 1.
18
For two joined Bézier curves, the control points are P1, P2, P3, P4
and P4, P5, P6, P7. For G1 continuity, points P3, P4, and P5
must be collinear.
P2
P3
P4
P1
P7
P5
P6
For C 1 continuity, P4 − P3 must equal P5 − P4.
Higher order Hermite and Bézier curves can be derived in a
similar manner, but are rarely used.
19
Cubic B-splines
Unlike Hermite and Bezier curves, cubic B-splines have C 2 continuity at the knots. Like Bezier curves, they have the convex
hull property.
If the spacing of the knots is uniform (equal separations in t),
then the spline is said to be a uniform B-spline.
A non-uniform B-spline has knot values which are not uniformly
distributed in the parameter t. In this case, the blending functions are not fixed, but vary from curve segment to segment.
Non-uniform B-splines are useful because they allow additional
flexibility in controlling the curve.
20
Non-uniform rational B-splines (NURBS)
It is possible to define all of the curves seen so far using rational
polynomials. They can be thought of as polynomials in homogeneous coordinates:
x(t) =
X(t)
,
W (t)
y(t) =
Y (t)
,
W (t)
z(t) =
Z(t)
W (t)
Here, X(t), Y (t), and Z(t) are polynomials with control points
defined in homogeneous coordinates. Any non-rational polynomial can be transformed to a rational polynomial by setting
W (t) = 1.
NURBS, being defined in a homogeneous coordinate system, are
invariant under rotation, translation, scaling, and perspective
transformation. This means that all transformations can be
applied to the control points, with the curve being generated
afterwards. This is far more efficient than generating all the
line segments comprising the curve and then transforming all
of these.
21