MAE 152 Computer Graphics For Scientists and Engineers: Splines and Bezier Curves
MAE 152 Computer Graphics For Scientists and Engineers: Splines and Bezier Curves
\
|
=
) (
) (
) (
) (
u z
u y
u x
u Q
sequence knot uniform then , If
vector knot
sequence knot
i u
u u u u
u u u u u u
i
n n
n n
=
= s s s s =
) , , , , (
1 1 0
max 1 1 0 min
Parameterization
0
u
1
u
2
u
3
u
i
u
1 + i
u
m
u
) (u Y
) (
1
u Y
) (
0
u Y
) (
2
u Y
) (u Y
m
i 1 + i
1 0
, , 2 , 1 , 0 ), ( ) ( Y
), (
1
i
1
s s
=
=
s s
+
+
u
n i
u u
u u
Y u
u u u u Y
i i
i
i i
non-uniform
Re-parameterization
0
V
1
V
2
V
3
V
4
V
5
V
6
V
Interpolation
0
V
1
V
2
V
3
V
4
V
5
V
6
V
Approximation
Interpolation versus Approximation
0
y
1
y
2
y
3
y
4
y
5
y
6
y
) (
0
u Y ) (u Y
) (
5
u Y
u
6 = u
0 = u
\
|
+ + =
=
\
|
+ + + =
=
+
+
1
) 1 (
) 1 (
1
3 2 ) 1 (
) 0 (
) 1 (
) 0 (
i i i i i
i i i
i i i i i i
i i i
D d c b Y
D b Y
y d c b a Y
y a Y
5 ,..., 0 1 0
) (
3 2
= s s
+ + + =
i u
u d u c u b a u
i i i i
Y
i
1 1
1 1
) ( 2
2 ) ( 3
+ +
+ +
+ + =
=
=
=
i i i i i
i i i i i
i i
i i
D D y y d
D D y y c
D b
y a
1 2 3 4 5
Hermite Interpolation
Hermite Spline
Say the user provides
A cubic spline has degree 3, and is of the form:
For some constants a, b, c and d derived from the
control points, but how?
We have constraints:
The curve must pass through x
0
when t=0
The derivative must be x
0
when t=0
The curve must pass through x
1
when t=1
The derivative must be x
1
when t=1
d ct bt at x + + + =
2 3
1 0 1 0
, , , x x x x ' '
1 0
) )( 1 ( )
1 1
s s
+
+
o
o o
avrage hted weig
(y (2)
i i i i
y y y
directly specifying (3)
1
, ,
+ i i
y y y and through parabola a fitting e.g.
lly automatica D Computing
(1)
-1 i
i
1 i
y
i
y
1 + i
y
1 i
P
i
P
1 + i
P
How to specify slope D
i
Hermite Spline
A Hermite spline is a curve for which the user provides:
The endpoints of the curve
The parametric derivatives of the curve at the endpoints
The parametric derivatives are dx/dt, dy/dt, dz/dt
That is enough to define a cubic Hermite spline, more
derivatives are required for higher order curves
Hermite Spline
Solving for the unknowns gives:
Rearranging gives:
0
0
0 1 0 1
0 1 0 1
2 3 3
2 2
x d
x c
x x x x b
x x x x a
=
' =
' ' =
' + ' + + =
) 2 (
) ( x
) 1 3 2 (
) 3 2 (
2 3
0
2 3
1
2 3
0
2 3
1
t t t x
t t
t t x
t t x x
+ ' +
' +
+ +
+ =
| |
(
(
(
(
(
(
(
(
' ' =
1
0 1 2 1
0 0 1 1
1 0 3 2
0 0 3 2
2
3
0 1 0 1
t
t
t
x x x x x
or
Hermite curves in 2D and 3D
We have defined only 1D splines:
x = f(t:x
0
,x
1
,x
0
,x
1
)
For higher dimensions, define the control
points in higher dimensions (that is, as
vectors)
(
(
(
(
(
(
(
(
(
(
(
(
' '
' '
' '
=
(
(
(
1
0 1 2 1
0 0 1 1
1 0 3 2
0 0 3 2
2
3
0 1 0 1
0 1 0 1
0 1 0 1
t
t
t
z z z z
y y y y
x x x x
z
y
x
Basis Functions
A point on a Hermite curve is obtained by
multiplying each control point by some function
and summing
The functions are called basis functions
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
x1
x0
x'1
x'0
0
V
1
V
2
V
3
V
4
V
5
V
6
V
An interpolating cubic spline
) , (
)) ( ), ( ( ) (
i i i
i i i
y x V
u y u x u Q
=
=
Hermite and Cubic Spline Interpolation
(knots) joints at continuity
) 2 (
C
0
y
1
y
2
y
i
y
1 + i
y
m
y
) (
0
u Y
) (u Y
) (
1
u Y
m
) (
1
u Y
m m
i i
i i
i i
i i
y Y
y Y
m i Y Y
Y Y
y Y
y Y
=
=
s s =
=
=
=
) 1 (
) 0 (
1 1 ) 0 ( ) 1 (
) 0 ( ) 1 (
) 0 (
) 1 (
1
0 0
) 2 ( ) 2 (
1
) 1 ( ) 1 (
1
1
4 4 m
2
need two more Eqs to determine all coefficients
1 0 ) (
3 2
s s + + + = m i u d u c u b a u Y
i i i i i
: note
Spline Interpolation
0 ) 1 (
0 ) 0 (
) 2 (
1
) 2 (
0
=
=
m
Y
Y
Natural Spline
1 1
) ( 3 4
) ( 2
2 ) ( 3
2 6 2
1 1 1 1
1 1
1 1
1 1
s s
= + +
+ + =
=
=
=
= +
+ +
+ +
+ +
m i
y y D D D
D D y y d
D D y y c
D b
y a
c d c
i i i i i
i i i i i
i i i i i
i i
i i
i i i
tion, simplifica and on substituti By
(4)
0 ) 1 (
0 ) 0 (
) 1 (
) 0 (
) 0 ( ) 1 (
) 0 ( ) 1 (
) 0 (
) 1 (
) 2 (
1
) 2 (
0
1
0 0
) 2 ( ) 2 (
1
) 1 ( ) 1 (
1
1
=
=
=
=
=
=
=
=
m
m m
i i
i i
i i
i i
Y
Y
y Y
y Y
Y Y
Y Y
y Y
y Y
(8)
(7)
(6)
(5)
(4)
(3)
(2)
(1)
1 1 s s m i
3 2
t d t c t b a y
i i i i i
+ + + =
Deriving Natural Cubic Splines
) ( 3 2
(8) from Similarly,
) ( 3 2
tion, simplifica and on substituti By
0 2
(7), From
conditions - end Applying
1 1
0 1 1 0
0
= +
= +
=
m m m m
y y D D
y y D D
c
(
(
(
(
(
(
(
(
(
=
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
) ( 3
) ( 3
) ( 3
) ( 3
2 1
1 4 1
. . . .
1 4 1
1 4 1
1 4 1
1 2
1
2
0 2
0 1
1
0
m m
m m
m
y y
y y
y y
y y
D
D
D
Tri-Diagonal Matrix for Natural Cubic Spline
i
P
m
P
0
P
2
P
1
P
Homework
) ( 3 4
1 1 1 1 + +
= + +
i i i i i
y y D D D
(
(
(
(
(
(
(
(
(
=
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
) ( 3
) ( 3
) ( 3
) ( 3
4 1 1
1 4 1
. . . .
1 4 1
1 4 1
1 4 1
1 1 4
1 0
2
0 2
1
1
0
m
m m
m
m
y y
y y
y y
y y
D
D
D
Closed Curves
Bezier Curves
An alternative to splines
M. Bezier was a French mathematician who worked
for the Renault motor car company.
He invented his curves to allow his firms computers
to describe the shape of car bodies.
? and provide to How
4 1
R R
1
P
4
P
1
R
4
R
mation Approxi
and
! ! ! points control additional two provide , and providing of Instead
3 2
4 1
P P
R R
1
P
4
P
2
P
3
P
Bezier Approximation
Bezier curves
Typically, cubic polynomials
Similar to Hermite interpolation
Special way of specifying end tangents
Requires special set of coefficients
Need four points
Two at the ends of a segment
Two control tangent vectors
Bezier curves
Control polygon: control points connected to each
other
Easy to generalize to higher order
Insert more control points
Hermite third order only
De Casteljau algorithm
Can compute any point on the curve in a
few iterations
No polynomials, pure geometry
Repeated linear interpolation
Repeated order of the curve times
The algorithm can be used as definition of
the curve
De Casteljau algorithm
Third order, u=0.75
De Casteljau algorithm
De Casteljau algorithm
De Casteljau algorithm
De Casteljau Algorithm
3
P
1
P
2
P
t
t 1
t 1
t 1
t 1
t 1
t
t
t
t
0
P
0
P
1
P
2
P
3
P
t 1
t
t 1
t
t 1
t
1 0
) 1 ( tP P t +
2 1
) 1 ( tP P t +
3 2
) 1 ( tP P t +
t 1
t
t 1
t
2
2
1 0
2
) 1 ( 2 ) 1 (
P t
tP t P t
+
+
3
2
2 1
2
) 1 ( 2 ) 1 (
P t
tP t P t
+
+
t 1
t
3
3
2
2
1
2
0
3
) 1 ( 3
) 1 ( 3
) 1 (
P t
P t t
tP t
P t
+
+
+
i i
i
t t
i
=
|
|
.
|
\
|
3
3
0
) 1 (
3
0
1
1
3
) 1 ( t
2
) 1 ( 3 -t t
3
t
) 1 ( 3
2
-t t
Now,
1 ) 1 (
3
3
3
0
=
|
|
.
|
\
|
=
i i
i
t t
i
What does it mean ?
| |
1 0 ) 1 (
3
) 1 ( 3 ) 1 ( 3 ) 1 ( ) (
0 0 0 1
0 0 3 3
0 3 6 3
1 3 3 1
1 ) (
3
3
0
4
3
3
2
2
2
1
3
4
3
2
1
2 3
s s
|
|
.
|
\
|
=
+ + + =
=
(
(
(
(
(
(
(
(
t , P t t
i
P t P -t t P -t t P t t Q
G M T
P
P
P
P
t t t t Q
i
i i
i
b b
3
)) 1 ( ( t t +
Bezier Polynomial Function
i n i
in
t t
i n i
n
t B
= ) 1 .( .
)! ( !
!
) (
Parametric equations for x(t),y(t)
) ( . ) (
0
t B x t x
in
n
i
i
=
=
) ( . ) (
0
t B y t y
in
n
i
i
=
=
Some Bezier Curves
Bezier Curves - properties
Not all of the control points are on the line
Some just attract it towards themselves
Points have influence over the course of the line
Influence (attraction) is calculated from a
polynomial expression
(show demo applet)
1
P
3
P
2
P
4
P
Convex Hull property
Bezier Curve Properties
The first and last control points are interpolated
The tangent to the curve at the first control point is along
the line joining the first and second control points
The tangent at the last control point is along the line
joining the second last and last control points
The curve lies entirely within the convex hull of its control
points
The Bernstein polynomials (the basis functions) sum to 1 and are
everywhere positive
They can be rendered in many ways
E.g.: Convert to line segments with a subdivision algorithm
Disadvantages
The degree of the Bezier curve depends on the
number of control points.
The Bezier curve lacks local control. Changing
the position of one control point affects the entire
curve.
Invariance
Translational invariance means that translating
the control points and then evaluating the curve is
the same as evaluating and then translating the
curve
Rotational invariance means that rotating the
control points and then evaluating the curve is the
same as evaluating and then rotating the curve
These properties are essential for parametric
curves used in graphics
It is easy to prove that Bezier curves, Hermite
curves and everything else we will study are
translation and rotation invariant
Longer Curves
A single cubic Bezier or Hermite curve can only capture a
small class of curves
At most 2 inflection points
One solution is to raise the degree
Allows more control, at the expense of more control points
and higher degree polynomials
Control is not local, one control point influences entire curve
Alternate, most common solution is to join pieces of cubic
curve together into piecewise cubic curves
Total curve can be broken into pieces, each of which is cubic
Local control: Each control point only influences a limited
part of the curve
Interaction and design is much easier
Piecewise Bezier Curve
knot
P
0,0
P
0,1
P
0,2
P
0,3
P
1,0
P
1,1
P
1,2
P
1,3
Continuity
When two curves are joined, we typically want some
degree of continuity across the boundary (the knot)
C
0
, C-zero, point-wise continuous, curves share the same point
where they join
C
1
, C-one, continuous derivatives, curves share the same
parametric derivatives where they join
C
2
, C-two, continuous second derivatives, curves share the same
parametric second derivatives where they join
Higher orders possible
Question: How do we ensure that two Hermite curves are
C
1
across a knot?
Question: How do we ensure that two Bezier curves are
C
0
, or C
1
, or C
2
across a knot?
Achieving Continuity
For Hermite curves, the user specifies the derivatives, so
C
1
is achieved simply by sharing points and derivatives
across the knot
For Bezier curves:
They interpolate their endpoints, so C
0
is achieved by sharing
control points
The parametric derivative is a constant multiple of the vector
joining the first/last 2 control points
So C
1
is achieved by setting P
0,3
=P
1,0
=J, and making P
0,2
and J
and P
1,1
collinear, with J-P
0,2
=P
1,1
-J
C
2
comes from further constraints on P
0,1
and P
1,2
Bezier Continuity
P
0,0
P
0,1
P
0,2
J
P
1,1
P
1,2
P
1,3
Disclaimer: PowerPoint curves are not Bezier curves,
they are interpolating piecewise quadratic curves! This
diagram is an approximation.
Problem with Bezier Curves
To make a long continuous curve with Bezier
segments requires using many segments
Maintaining continuity requires constraints on the
control point positions
The user cannot arbitrarily move control vertices and
automatically maintain continuity
The constraints must be explicitly maintained
It is not intuitive to have control points that are not free
Bezier Basis Functions for d=3
0
0.2
0.4
0.6
0.8
1
1.2
B0
B1
B2
B3
Bezier Curves in OpenGL
OpenGL supports Beziers through mechanism called evaluators used
to compute the blending functions, b
i
(u), of any degree.
Smooth curves and surfaces are drawn by approximating them with
large number of small line segments or polygons. Described
mathematically by a small number of parameters such as control points.
1D Bezier curves can also be used to define paths in time for animation
Evaluator is a way to compute points on a curve or surface using only
control points. They do not require uniform spacing of u. Bezier curves
can then be rendered at any precision.
Evaluators
A Bezier curve is a vector-valued function of one
variable
C(u) = [X(u) Y(u) Z(u)]
and a Bezier surface patch is a vector-valued
function of two variable
S(u,v) = [X(u,v) Y(u,v) Z(u,v)]
To use evaluator
first define the function C(u) or S(u,v)
then use the glEvalCoord{12}() command
Berstein Polynomial & Bezier Curve
( )
i
n
i
n
i
P u B u C ) (
0 =
=
( )
i n i n
i
u u
i
n
u B
|
|
.
|
\
|
= ) 1 (
|
|
.
|
\
|
1 2
1
u u
u u
C
One-Dimensional Evaluators
GLfloat ctrlpoints[4][3] = {...};
void init(void) {
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0,
3, 4, &ctrlpoints[0][0]);
}
void display(void) {
glBegin(GL_LINE_STRIP);
for(i=0; i<=30; i++)
glEvalCoord1f((GLfloat)i/30.0);
glEnd();
}
Defining 1-D Evaluator
glMap1(target,u1,u2,stride,order,points);
target: tells what the control points represent
u1,u2: the range of the variable u
stride: the number of floating-point values to advance in the
data between one control point and the next
order: the degree plus one, and it should agree with the
number of control points
points: pointer to the first coordinate of the first control point
Evaluating 1-D Evaluator
glEvalCoord1(u);
glEvalCoord1v(*u);
Causes evaluation of the enabled maps
u: the value of the domain coordinate
More than one evaluator can be defined and evaluated
at a time.
(ex) GL_MAP1_VERTEX_3 and GL_MAP1_COLOR_4
In this case, calls to glEvalCoord1() generates both a
position and a color.
point ctrlpts[ ] = { . } ;
glMaplf ( GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, ctrlpts);
glEnable (GL_MAP1_VERTEX_3);
/* GL_MAP1_VERTEX_3 specifies data type for ctrlpts ,
range of u = [ 0.0, 1.0], 3 is the number of values between
control points , (order = degree +1) = 4 */
/* With evaluator enabled, draw line segments for Bezier curve */
e.g. /* define and enable 1D evaluator for Bezier cubic curve */
glBegin (GL_LINE_STRIP);
for ( i = 0; i <= 30; i ++)
glEvalCoord1f ( (Glfloat) i/30.0);
glEnd ( )
One-Dimensional Grid and Its Eval.
define a one-dimensional evenly spaced grid using
glMapGrid1*(), and then evaluate the (part of) grid
points using glEvalMesh1()
glMapGrid1(n, u1, u2);
defines a grid that goes from u1 to u2 in n steps.
glEvalMesh1(mode, p1, p2);
mode: GL_POINT or GL_LINE
evaluates from integer indices p1 to p2 with evenly
spaced coordinate
Bezier Surface
( )
ij
m
j
n
i
m
j
n
i
P v B u B v u S ) ( ) ( ,
0 0 = =
=
Two-Dimensional Evaluators
Everything is similar to the one-dimensional
case, except that all the commands must
take two parameters, u and v, into account
1. Define evaluator(s) with glMap2*()
2. Enable them with glEnable()
3. Invoke them by calling glEvalCoord2()
between a glBegin() and glEnd() or by
specifying and applying a mesh with
glMapGrid2() and glEvalMesh2()
Defining and Evaluating
glMap2(target, u1, u2, ustride, uorder,
v1, v2, vstride, vorder, points);
glEvalCoord2(u, v);
glEvalCoord2v(*values);
Example
Grid and Its Evaluation
glMapGrid2(nu, u1, u2, nv, v1, v2);
glEvalMesh2(mode, i1, i2, j1, j2);
Using Evaluators for Textures
GLfloat ctrlpoints[4][4][3] = {...};
GLfloat texpts[2][2][2] = {...};
void init(void) {
glMap2f(GL_MAP2_VERTEX_3,...,
&ctrlpoints[0][0][0]);
glMap2f(GL_MAP2_TEXTURE_COORD_2,...,
&texpts[0][0][0]);
glEnable(GL_ MAP2_VERTEX_3);
glEnable(GL_MAP2_TEXTURE_COORD_2);
glMapGrid2f(...);
}
void display(void) {
glEvalMesh2(...);
}
End Of Curves