Download presentation
Presentation is loading. Please wait.
Published byLester Reynolds Modified over 9 years ago
1
Bézier Algorithms & Properties Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, March 3, 2004
2
3 Mar 2004CS 481/6812 Review: Bé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.
3
3 Mar 2004CS 481/6813 Review: Bézier Curves & Surfaces [2/2] A Bézier curve can be defined using repeated lirping. Example: 3 control points (P 0, P 1, P 2 ). f(0) = P 0 (first control pt.); f(1) = P 2 (last control pt.). To find other function values (for a given value of t): Lirp between P 0 & P 1. Lirp between P 1 & P 2 (same t). Lirp between above two values (same t) to get point on curve. P0P0 P1P1 P2P2 P0P0 P1P1 P2P2
4
3 Mar 2004CS 481/6814 Review: OpenGL 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.
5
3 Mar 2004CS 481/6815 Bézier Algorithms: Overview 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.
6
3 Mar 2004CS 481/6816 Bézier Algorithms: De Casteljau Alg. [1/4] Recall that a Bézier curve can be described in terms of repeated linear interpolation. Example: 4 control points (P 0, P 1, P 2, P 3 ). f(0) = P 0 (first control pt.); f(1) = P 3 (last control pt.). To find other function values (for a given value of t): Lirp between P 0 & P 1, P 1 & P 2, and P 2 & P 3. Lirp between 1 st & 2 nd point above and between 2 nd & 3 rd. Lirp between the above two values to get the point on the curve. P0P0 P1P1 P2P2 P3P3
7
3 Mar 2004CS 481/6817 Bé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. lirp P0P0 P1P1 P2P2 P3P3 P4P4 Point on curve
8
3 Mar 2004CS 481/6818 Bé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.
9
3 Mar 2004CS 481/6819 Bézier Algorithms: De Casteljau Alg. [4/4] Set-Up for Sample Code Number of control points: const int ncp. Array: double v[ncp][ncp][3]; Last index above indicates x, y or z. (Make the “ 3 ” a “ 2 ” for 2-D.) Control points given in v[0][0 … ncp-1][0 … 2]. Parameter: double t. Already written: double lirp(double t, double a, double b). Code for (int c=0; c<3; ++c) // Calc x, y, z independently for (int i=1; i<ncp; ++i) for (int k=0; k<ncp-i; ++k) v[i][k][c] = lirp(t, v[i-1][k][c], v[i-1][k+1][c]); Point on curve is now in v[ncp-1][0][0 … 2].
10
3 Mar 2004CS 481/68110 Bézier Algorithms: Bernstein 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 (P 0, P 1, …, P n–1 ), then a Bézier curve is parameterized by a polynomial of degree n–1. For two control points (P 0, P 1 ), the polynomial describing the Bézier Curve is P 0 ·(1–t) + P 1 ·t. This is just the lirping formula (right?). This is really two polynomials: one for x, and one for y. For three control points (P 0, P 1, P 2 ), the polynomial is P 0 ·(1–t) 2 + P 1 ·2(1–t)t + P 2 ·t 2. For four control points the polynomial is P 0 ·(1–t) 3 + P 1 ·3(1–t) 2 t + P 2 ·3(1–t)t 2 + P 3 ·t 3.
11
3 Mar 2004CS 481/68111 Bézier Algorithms: Bernstein Polynomials [2/3] Again, for four control points the polynomial is P 0 ·(1–t) 3 + P 1 ·3(1–t) 2 t + P 2 ·3(1–t)t 2 + P 3 ·t 3. This is made up of pieces called Bernstein polynomials. B 3 0 (t) = (1–t) 3. B 3 1 (t) = 3(1–t) 2 t. B 3 2 (t) = 3(1–t)t 2. B 3 3 (t) = t 3. The pattern: Descending powers of (1–t). Ascending powers of t. Coefficients are binomial coefficients. Found in Pascal’s Triangle.
12
3 Mar 2004CS 481/68112 Bézier Algorithms: Bernstein 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). Pro’s & Con’s of Bernstein Polynomials vs. de C’s 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.
13
3 Mar 2004CS 481/68113 Bézier Algorithms: Surfaces [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 formulas: P 0,0 ·(1–t) 2 + P 0,1 ·2(1–t)t + P 0,2 ·t 2 P 1,0 ·(1–t) 2 + P 1,1 ·2(1–t)t + P 1,2 ·t 2 P 2,0 ·(1–t) 2 + P 2,1 ·2(1–t)t + P 2,2 ·t 2 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: [ P 0,0 ·(1–t) 2 + P 0,1 ·2(1–t)t + P 0,2 ·t 2 ]·(1–s) 2 + [ P 1,0 ·(1–t) 2 + P 1,1 ·2(1–t)t + P 1,2 ·t 2 ]·2(1–s)s + [ P 2,0 ·(1–t) 2 + P 2,1 ·2(1–t)t + P 2,2 ·t 2 ]·s 2 P 0,0 P 0,1 P 0,2 P 1,0 P 1,1 P 1,2 P 2,0 P 2,1 P 2,2
14
3 Mar 2004CS 481/68114 Bézier Algorithms: Surfaces [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.
15
3 Mar 2004CS 481/68115 Bézier Properties: Overview 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
16
3 Mar 2004CS 481/68116 Bé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. P1P1 P0P0 P2P2 P1P1 P0P0 Q0Q0 Q1Q1 P2P2 Q2Q2
17
3 Mar 2004CS 481/68117 Bé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: P1P1 P0P0 P2P2 P1P1 P0P0 Q0Q0 Q1Q1 P2P2 Q2Q2
18
3 Mar 2004CS 481/68118 Bé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.
19
3 Mar 2004CS 481/68119 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. Bézier Properties: Convex-Hull Property P1P1 P0P0 P2P2 P1P1 P0P0 P2P2 PointsConvex hull P1P1 P0P0 P2P2
20
3 Mar 2004CS 481/68120 Bé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.
21
3 Mar 2004CS 481/68121 Building Better Curves: How 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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.