Title: Bzier Algorithms
1Bézier Algorithms Properties
- Glenn G. ChappellCHAPPELLG_at_member.ams.org
- U. of Alaska Fairbanks
- CS 481/681 Lecture Notes
- Wednesday, March 3, 2004
2ReviewBézier Curves Surfaces 1/2
- Our first type of spline is the Bézier
curve/surface. - Bézier curves surfaces were developed around
1960, for use in CAD/CAM. - First application automobile design.
- PostScript and TrueType both describe characters
with Bézier curves. - A Bézier curve is a parametric curve described by
polynomials based on control points. - Any number of control points may be used. 3 4
are common. - Degree of polynomials number of points 1.
- Several Bézier curves can easily be glued
together in a way that makes the curve as a whole
smooth. - Bézier curves are approximating curves. A Bézier
curve passes through its first and last control
points, but, in general, no others. - A Bézier surface patch can be formed by starting
with a grid of control points, drawing curves in
one direction, and then in the perpendicular
direction, using points on the already drawn
curves as control points.
3ReviewBézier Curves Surfaces 2/2
- A Bézier curve can be defined using repeated
lirping. - Example 3 control points (P0, P1, P2).
- f(0) P0 (first control pt.) f(1) P2 (last
control pt.). - To find other function values (for a given value
of t) - Lirp between P0 P1.
- Lirp between P1 P2 (same t).
- Lirp between above two values (same t) to get
point on curve.
P2
P2
P0
P0
P1
P1
4ReviewOpenGL Evaluators
- OpenGL evaluators compute Bézier curves
surfaces. - When using an evaluator, you specify control
points. - Set the usual graphics state options any way you
like. - OpenGL does the glVertex calls for you.
- Once an evaluator is initialized and enabled, you
can - Use the evaluator to compute a single point on
the curve/surface (and, typically, do a glVertex
with it). - Use glEvalCoord.
- Use the evaluator to draw the whole
curve/surface. - Set up an evaluator grid with glMapGrid.
- Draw with glEvalMesh.
- When drawing Bézier surfaces, OpenGL can compute
vertex normals for you. - Enable GL_AUTO_NORMAL.
- Evaluators can also be used to set the color, as
well as other vertex-related states.
5Bézier AlgorithmsOverview
- Now we discuss how Bézier curves are drawn.
- We will cover two algorithms
- The de Casteljau Algorithm
- Uses the repeated-lirping description of the
curve. - Using Bernstein Polynomials
- Compute the polynomials that describe the curve.
- This is generally how OpenGL evaluators are
implemented.
6Bézier AlgorithmsDe Casteljau Alg. 1/4
- Recall that a Bézier curve can be described in
terms of repeated linear interpolation. - Example 4 control points (P0, P1, P2, P3).
- f(0) P0 (first control pt.) f(1) P3 (last
control pt.). - To find other function values (for a given value
of t) - Lirp between P0 P1, P1 P2, and P2 P3.
- Lirp between 1st 2nd point above and between
2nd 3rd. - Lirp between the above two values to get the
point on the curve.
P2
P0
P1
P3
7Bézier Algorithms De Casteljau Alg. 2/4
- The de Casteljau Algorithm computes a point on a
Bézier curve using this repeated lirping
procedure. - Each lirp is done using the same value of t.
- x, y, and z are computed separately.
P0
P1
P2
P3
P4
lirp
lirp
lirp
lirp
lirp
lirp
lirp
lirp
lirp
lirp
Point on curve
8Bézier Algorithms De Casteljau Alg. 3/4
- To draw a curve using the de Casteljau Algorithm
- Set up the control points in an array as usual.
- Have a loop to draw the curve.
- This should probably be inside a glBegin/glEnd.
- The parameter (t) should go from 0 to 1.
- The step size will depend on the desired output
quality. - It is generally best to have an integer loop
counter, then, in each iteration, find t by
multiplying. - For each value of the parameter, do the repeated
lirping procedure to calculate the point on the
curve. - If the curve does not change, pre-computing
points on the curve is a good idea. - Use a display list, maybe?
- Next Sample code to do the repeated lirping.
9Bézier Algorithms De Casteljau Alg. 4/4
- Set-Up for Sample Code
- Number of control points const int ncp.
- Array double vncpncp3
- Last index above indicates x, y or z. (Make the
3 a 2 for 2-D.) - Control points given in v00ncp-102.
- Parameter double t.
- Already written double lirp(double t, double a,
double b). - Code
- for (int c0 clt3 c) // Calc x, y, z
independently - for (int i1 iltncp i)
- for (int k0 kltncp-i k)
- vikc lirp(t, vi-1kc,
vi-1k1c) - Point on curve is now in vncp-1002.
10Bézier AlgorithmsBernstein Polynomials 1/3
- Another way to draw a Bézier curve is to use the
polynomial that describes it to compute
coordinates of points. - If there are n control points (P0, P1, , Pn1),
then a Bézier curve is parameterized by a
polynomial of degree n1. - For two control points (P0, P1), the polynomial
describing the Bézier Curve is P0(1t) P1t. - This is just the lirping formula (right?).
- This is really two polynomials one for x, and
one for y. - For three control points (P0, P1 , P2), the
polynomial isP0(1t)2 P12(1t)t P2t2. - For four control points the polynomial
isP0(1t)3 P13(1t)2t P23(1t)t2 P3t3.
11Bézier AlgorithmsBernstein Polynomials 2/3
- Again, for four control points the polynomial
isP0(1t)3 P13(1t)2t P23(1t)t2 P3t3. - This is made up of pieces called Bernstein
polynomials. - B30(t) (1t)3.
- B31(t) 3(1t)2t.
- B32(t) 3(1t)t2.
- B33(t) t3.
- The pattern
- Descending powers of (1t).
- Ascending powers of t.
- Coefficients are binomial coefficients.
- Found in Pascals Triangle.
12Bézier AlgorithmsBernstein Polynomials 3/3
- Using a polynomial to draw a Bézier curve in a
program - Have a loop in which t starts at 0 and goes up to
1, as usual. - For each value of t, find the point on the curve
- Compute (1-t), since you probably need to use it
several times. - Compute the x and y polynomial functions, using t
and (1-t). - Pros Cons of Bernstein Polynomials vs. de Cs
Alg. - ??? In practice, using the Bernstein Polynomials
is faster than the de Casteljau Algorithm. - ? But it is tricky to generalize the
Bernstein-polynomial method to an arbitrary
number of control points. - The code we looked at for the de Casteljau
Algorithm works for any number of control points. - However, that code slows down rapidly as the
number of control points becomes large.
13Bézier AlgorithmsSurfaces 1/2
- The way we described Bézier surfaces last time
suggests how to extend curve-drawing algorithms
to surfaces. - Say we have a grid of 9 control points, as shown.
- The horizontal curves have the following
formulasP0,0(1t)2 P0,12(1t)t
P0,2t2P1,0(1t)2 P1,12(1t)t
P1,2t2P2,0(1t)2 P2,12(1t)t P2,2t2 - Now we use points on these curves as control
points. Let our vertical parameter be s. We
obtain the following formula for a Bézier
patch P0,0(1t)2 P0,12(1t)t P0,2t2
(1s)2 P1,0(1t)2 P1,12(1t)t P1,2t2
2(1s)s P2,0(1t)2 P2,12(1t)t
P2,2t2 s2
P0,0
P0,1
P0,2
P1,0
P1,1
P1,2
P2,0
P2,1
P2,2
14Bézier AlgorithmsSurfaces 2/2
- Given the formulas on the previous slide, we can
draw a Bézier patch using two for-loops. - Probably using GL_TRIANGLE_STRIP.
- So each row has to be given twice (right?).
- A similar generalization applies to the de
Casteljau Algorithm. - However, that algorithm is not terribly efficient.
15Bézier PropertiesOverview
- We will now look at some properties of Bézier
curves. - Generally Good Properties ?
- Endpoint Interpolation
- Smooth Joining
- Affine Invariance
- Convex-Hull Property
- Generally Bad Properties ?
- Not Interpolating
- No Local Control
16Bézier Properties? Endpoint Interpolation
- Bézier curve generally do not pass through all
control points. - However, they do pass through the first last
control points. - So, to make two Bézier curves join, make the
first control point of one equal to the last
control point of the other. - This may not result in a smooth curve overall.
P0
P2
P1
Q0
P2
P0
Q2
P1
Q1
17Bézier Properties? Easy Smooth Joining
- At its start, the velocity vector (first
derivative) of a Bézier curve points from the
first control point, towards the second. - At its end, the velocity vector points from the
last control point away from the next-to-last. - To make two Bézier curves join smoothly put the
last two control points of one and the first two
of the other in a line, as shown
P0
P2
P1
Q1
P2
P0
Q2
Q0
P1
18Bézier Properties? Affine Invariance
- An affine transformation is a transformation that
can be produced by doing a linear transformation
followed by a translation. - All of the transformations we have dealt with,
except for perspective projection, are affine.
These include - Translation.
- Rotation.
- Scaling.
- Shearing.
- Reflection.
- Bézier curves have the property that applying an
affine transformation to each control points
results in the same transformation being applied
to every point on the curve. - For example, to rotate a Bézier curve, apply a
rotation to the control points. - In short Transformations act the way you want
them to.
19Bézier Properties? Convex-Hull Property
- The convex hull of a set of points is the
smallest convex region containing them. - Informally speaking, lasso (or shrink-wrap) the
points the region inside the lasso is the convex
hull. - A Bézier curve lies entirely in the convex hull
of its control points. - This property makes it easy to specify where a
curve will not go. - Smooth interpolating splines never have this
property.
P0
P2
P0
P2
Points
Convex hull
P1
P1
P0
P2
P1
20Bézier Properties? Not-So-Good Stuff
- Again Bézier curves do not interpolate all their
control points. - So we can easily specify where it does not go,
but not where it does go. - Bézier curves also do not have local control.
- A curve has local control if moving a single
control point only changes a small part of the
curve (the part near the control point). - Moving any control point on a Bézier curve
changes the whole curve. - This is the main reason we do not use Bézier
curves with a large number of control points. - Instead, we piece together several 3- or 4-point
Bézier curves in a smooth way. - This multiple-Bézier curve does have local
control.
21Building Better CurvesHow to Improve on Bézier?
- The biggest problems with Bézier curves are
- Lack of local control.
- High degree, if there are a large number of
control points. - Lack of interpolation (sometimes a problem,
sometimes not). - Better curve 1 B-spline.
- Parametric curve described by polynomials based
on control points. - Has affine invariance local control.
- Has same degree regardless of number of control
points. - Approximating, has convex-hull property.
- Better curve 2 Catmull-Rom spline.
- Parametric curve described by polynomials based
on control points. - Has affine invariance local control.
- Has same degree (3) regardless of number of
control points. - Interpolating, no convex-hull property, (and a
bit tough to get just right). - Better curve 3 NURBS (Non-Uniform Rational
B-Spline). - Parametric curve described by rational functions
based on control points. - Has affine invariance local control.
- Very general adaptable, but thus somewhat
tougher to use. - Built into GLU.