Download presentation
Presentation is loading. Please wait.
Published byHarvey Wright Modified over 9 years ago
1
1 Bezier Curves and Surfaces © Jeff Parker, Nov 2011
2
Outline We often wish to generate curves and surfaces To create objects To create movement e.g. Genesis Project To provide transitions We will look at a number of ways to generate curves We will focus on various parametric cubics
3
Review We often wish to generate curves and surfaces There are a number of (conflicting) goals Interpolate (include) a set of arbitrary points Easy and efficient to compute Smooth Local Control Easy to deal with We may need to compute derivatives It is hard to get all of these We will discuss ways to achieve some of these
4
4 History The Bezier curves and surfaces were developed twice: Pierre Bézier, at Renault Paul de Casteljau, at Citroën Used to bend sheet metal or wood to achieve a smooth shape
5
Background: Interpolation Given a set of n points (x i, y i ) we may be able to define a polynomial that goes through each point. Solution: Lagrange Polynomial Assumes no two points with the same x but different y Thus cannot draw circle Interpolate set of arbitrary points Easy and efficient to compute Smooth Local Control
6
6 Runge Phenomena Try to approximate the red curve with polynomials Interpolate (hit curve) at evenly spaced x values
7
Runge Phenomena Interpolate at evenly spaced points Difficult to get local control with high order polynomials Interpolate set of arbitrary points Easy and efficient to compute Smooth Local Control
8
Runge Phenomena To avoid this We don't always interpolate We break curve into small polynomial pieces Interpolate set of arbitrary points Easy and efficient to compute Smooth Local Control
9
9 Terminology Interpolation vs. Approximation
10
Functions Three main ways to define a curve Function: y = x 3 + 3x A function must be single valued Cannot draw vertical line or circles with function Implicit function: x 2 + y 2 + xy= 25 In general case, can't find all points that satisfy Parametric Function: (x, y) = (5 cos(t), 5 sin(t)) What we will use tonight
11
Parametric Functions We will be exploring Parametric Curves Parametric Surfaces are similar Natural parameterization Moves with curve length
12
Sample Surface Parametric map the unit square to the sphere
13
Linear Bezier Curve We wrote line segments as weighted sum of endpoints This is the convex sum of the two end points The curves below are defined on [0..1], sum to 1 Blending Functions
14
Linear Bezier Curve In the expression, the terms p 0 and p 1 are vectors, and their weighted sum is a vector This is a powerful technique, and we will use it all night Blending Functions
15
Piece these together Piece together a curve that connects a set of points p1p1 p2p2 p3p3 p4p4 p0p0
16
Piece these together Piece together a curve that connects a set of points p1p1 p2p2 p3p3 p4p4 p0p0
17
Piece these together Create series of equations p1p1 p2p2 p0p0 p3p3 p4p4 p1p1 p2p2 p3p3 p4p4 p0p0 Blending Functions
18
Piece these together Create series of equations p1p1 p2p2 p0p0 p3p3 p4p4 p1p1 p2p2 p3p3 p4p4 p0p0 Interpolate set of arbitrary points Easy and efficient to compute Smooth Local Control Blending Functions
19
Piece these together Create series of equations p1p1 p2p2 p0p0 p3p3 p4p4 p1p1 p2p2 p3p3 p4p4 p0p0 TInterpolate set of arbitrary points TEasy and efficient to compute FSmooth – Nope - sharp "corners" TLocal Control Blending Functions
20
Piece these together Create series of equations p1p1 p2p2 p0p0 p3p3 p4p4 p1p1 p2p2 p3p3 p4p4 p0p0 What do we want from the blending functions? Active Blending Functions should sum to 1 Nice to have all non-negative terms Blending Functions
21
Terminology Not continuous at break Not differentiable at corner Next: C(1) vs G(1)
22
Geometric Continuity
23
23 Cubics We will focus on Cubic curves That is, curves with cubic blending functions Reasons These allow C(1) and even C(2) continuity Allow minimum-curvature interpolants to a set of points Can define position and curvature at two ends Cubic Polynomials are in the sweet spot: Smooth, and easy to compute Implemented with 4x4 matrices, just like rest of OpenGL
24
24 Bezier Animation http://zonalandeducation.com/mmts/curveFitting/be zierCurves/bca2/Bezier1Animation2.html
25
25 Note rate of movement
26
26 Bezier Curve We will look at Bezier Curves in some detail tonight There are different ways to think about them: All paths lead to the same curves De Castlejau Algorithm (recursive subdivision) Bernstein Polynomials Matrix Form Cubic equations All have their uses, and you will see all in practice
27
27 De Casteljau Algorithm Compute points on the curve without evaluating polynomials Can use the midpoints, so only need to shift right
28
28 De Casteljau's Method Compute points on the curve without evaluating polynomials Can use the midpoints, so only need to shift right
29
29 De Casteljau's Method Gives simple recursive method to draw curve Keep dividing until each subpiece of the curve is almost straight
30
30 Recursive Drawing Algorithm We take original four control points Recursively subdivide, just using adds and shifts Get two Beziers, with 7 control points Curve lies inside the convex hull of control points Continue until the convex hull is one pixel wide At each step, subcurves are shorter are much less wide Can make this formal
31
31 Terminology The Bezier interpolates the first and fourth control point That is, the curve passes through them The middle two control points draw the curve towards them
32
De Casteljau Let's spell out what this means Notation differs from figure
33
Expand one level Derivation is similar
34
Find third level
35
35 Bezier Curve There are different ways to think about them: De Castlejau Algorithm (recursive subdivision) Bernstein Polynomials Matrix Form Cubic equations All have their uses, and you will see all in practice
36
36 Bernstein Polynomials We write a Bezier as the weighted sum of control points The control points are multiplied by Bernstein polynomials Convex sum of polynomials with values in [0..1] that sum to 1 Each polynomial pulls curve towards it's control point
37
What does it mean? We use these blending functions to decide the amount of contribution from each control point. Note that the terms add up to one
38
38 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Why Polynomials? Easy to evaluate Continuous and differentiable everywhere Must worry about continuity at join points including continuity of derivatives p(u) q(u) join point p(1) = q(0) but p’(1) q’(0)
39
Bezier Polynomials sum to one So each point on the curve is a convex sum of the control points Thus the curve lies inside the convex hull of the control points
40
40 Convex Hull Check that the curve remains inside the convex hull of the control points in our examples Also obvious from De Casteljau's Algorithm
41
41 Bezier Curve All paths lead to the same point De Castlejau Algorithm (recursive subdivision) Bernstein Polynomials Matrix Form Cubic equations All have their uses, and you will see all in practice
42
How did we pick blending functions? What do we want from blending functions? Active Blending Functions Nice to have all non-negative terms Functions should be smooth (rather than the pyramids) Where did we get these blending functions?
43
Review: Blending function for line We know p 0 and p 1. We want vectors a 0 and a 1 so that
44
Blending function for the line We could solve this by hand: a 0 = p 0, etc. But let's evolve a general method Both p and a are vectors
45
We know p, wish to find a To solve for p, can invert the Constraint Matrix, C to find the Blending Matrix, B
46
Blending function for the line We know p, wish to find terms for a for blending Multiply on left by B and vector [1 t] Blending Functions
47
Blending functions for Bezier Know p 0, p 1, p 2, and p 3, want vectors a 0, a 1, a 2, and a 3 so that our curve has the form What do we know? We know that f(t) interpolates p 0 and p 3 at t=0 and t=1
48
Constraint Matrix for Bezier We also know that the slope at the ends is 3(p 1 -p 0 ) Compute slope: Evaluate at t=0 and t=1
49
Constraint Matrix for Bezier Now we have a constraint matrix C: find it’s inverse B
50
Apply Constraint Matrix Apply the vector [1 u u 2 u 3 ] to matrix B
51
51 Bezier Curve All paths lead to the same point De Castlejau Algorithm (recursive subdivision) Bernstein Polynomials Matrix Form Cubic equations All have their uses, and you will see all in practice
52
Derive the values a i Another way to look at this:
53
53 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 NURBS Nonuniform Rational B-Spline curves and surfaces add a fourth variable w to x,y,z Can interpret as weight to give more importance to some control data Can also interpret as moving to homogeneous coordinate Requires a perspective division NURBS act correctly for perspective viewing Quadrics are a special case of NURBS
54
NURBS Non-Uniform Rational B-Splines Note that Rational is usually a restriction Rational numbers vs all real numbers. Here it is an extension: Projective Geometry Example: we wish to draw a unit circle No exact match with Cubic Beziers – can get close However, if we use projective space…
55
North and south pole and point at (Eastern) infinity We only need a quadratic Bezier for 3 points Quadratic Bezier
56
But are these points on the unit circle? x y
57
The control points are weighted This gives NURBS more degrees of freedom Degree Elevation
58
Interpolating Cubic Use this technique to find a curve that interpolates control points Start by computing constraints: must hit p 0 at 0, p 1 at 1/3, p 2 at 2/3, p 3 at 1 p0p0 p1p1 p2p2 p3p3
59
Interpolating Cubic Use this technique to find a curve that interpolates control points Start by computing constraints: must hit p 0 at 0, p 1 at 1/3, p 2 at 2/3, p 3 at 1 p0p0 p1p1 p2p2 p3p3
60
60 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Interpolation Matrix Solving for c we find the interpolation matrix c=MIpc=MIp Note that M I does not depend on input data and can be used for each segment in x, y, and z
61
61 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Interpolating Multiple Segments use p = [p 0 p 1 p 2 p 3 ] T use p = [p 3 p 4 p 5 p 6 ] T Get continuity at join points but not continuity of derivatives
62
62 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Blending Functions Rewriting the equation for p(u) p(u)=u T c=u T M I p = b(u) T p where b(u) = [b 0 (u) b 1 (u) b 2 (u) b 3 (u)] T is an array of blending polynomials such that p(u) = b 0 (u)p 0 + b 1 (u)p 1 + b 2 (u)p 2 + b 3 (u)p 3 b 0 (u) = -4.5(u-1/3)(u-2/3)(u-1) b 1 (u) = 13.5u (u-2/3)(u-1) b 2 (u) = -13.5u (u-1/3)(u-1) b 3 (u) = 4.5u (u-1/3)(u-2/3)
63
63 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison- Wesley 2012 Lagrange Blending Functions These functions are not smooth Hence the interpolation polynomial is not smooth Are not limited to [0, 1] – thus not convex
64
64 Catmull-Rom We can get a similar effect with Bezier curves One way of auto-generating the right slopes to a set of interpolated points was introduced by Catmull and Rom Idea is to use slope between previous and next point as the slope at the current point. If distance between points is uneven, can overshoot
65
Cubic Hermite Spline Sometimes we want to avoid sharp corners Can define the slope at the endpoints Hermite Polynomials use a new blending functions to define curve p(0) p(1) p’(0)p’(1)
66
Hermite Polynomial
68
68 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Analysis Bezier form has advantages over interpolating form, derivatives need note be continuous at join points Can we do better? Go to higher order Bezier More work Derivative continuity still only approximate Supported by OpenGL Apply different conditions Tricky without letting order increase
69
69 Splines Approximate rather than interpolate (blue vs red curves) (Image is of a traditional spline used in boat building)
70
70 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 B-Splines Basis splines: use the data at p=[p i-2 p i-1 p i p i-1 ] T to define curve only between p i-1 and p i We can apply more continuity conditions to each segment For cubics, we can have continuity of function, first and second derivatives at join points - C(2) Cost is 3 times as much work for curves Add one new point each time rather than three For surfaces, we do 9 times as much work
71
71 Cubic B-spline p(u) = u T M S p = b(u) T p E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
72
72 Blending Functions convex hull property E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
73
73 Basis Functions In terms of the blending polynomials E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
74
Basis Functions
75
75 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison- Wesley 2012 B-Spline Patches defined over only 1/9 of region
76
76 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Splines and Basis If we examine the cubic B-spline from the perspective of each control (data) point, each interior point contributes (through the blending functions) to four segments We can rewrite p(u) in terms of the data points as defining the basis functions {B i (u)}
77
77 Generalizing Splines We can extend to splines of any degree Data and conditions do not have to given at equally spaced values (the knots) Nonuniform and uniform splines Can have repeated knots Can force spline to interpolate points Cox-deBoor recursion gives method of evaluation E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
78
78 Beziers in OpenGL We could evaluate Beziers by hand, given the formulas above. It is simpler to use Evaluators, provided by OpenGL Evaluators provide a way to use polynomial or rational polynomial mapping to produce vertices, normals, texture coordinates, and colors. The values produced by an evaluator are sent to further stages of GL processing just as if they had been presented using glVertex, glNormal, glTexCoord, and glColor commands, except that the generated values do not update the current normal, texture coordinates, or color. All polynomial or rational polynomial splines of any degree (up to the maximum degree supported by the GL implementation) can be described using evaluators. These include almost all splines used in computer graphics: B-splines, Bezier curves, Hermite splines, and so on. (From the man page)
79
Bezier Curve void drawCurve() { int i; GLfloat pts[4][3]; /* Copy the coordinates from balls to array */ for (i = 0; i < 4; i++) { pts[i][0] = (GLfloat)cp[i]->x; pts[i][1] = (GLfloat)wh - (GLfloat)cp[i]->y; pts[i][2] = (GLfloat)0.0; } // Define the evaluator glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &pts[0][0]); /* type, u_min, u_max, stride, num points, points */ glEnable(GL_MAP1_VERTEX_3); setLineColor(); glBegin(GL_LINE_STRIP); for (i = 0; i <= 30; i++) /* Evaluate the curve when u = i/30 */ glEvalCoord1f((GLfloat) i/ 30.0); glEnd();
80
Teapot
81
bteapot.c // vertices.h GLfloat vertices[306][3]={{1.4, 0.0, 2.4}, {1.4, -0.784, 2.4}, {0.784, -1.4, 2.4}, {0.0, -1.4, 2.4}, {1.3375, 0.0, 2.53125}, {1.3375, -0.749, 2.53125}, {0.749, -1.3375, 2.53125}, {0.0, -1.3375, 2.53125}, {1.4375, 0.0, 2.53125}, {1.4375, -0.805, 2.53125}, {0.805, -1.4375, 2.53125},... // patches.h int indices[32][4][4]={{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, {4, 17, 18, 19, 8, 20, 21, 22, 12, 23, 24, 25, 16, 26, 27, 28}, {19, 29, 30, 31, 22, 32, 33, 34, 25, 35, 36, 37, 28, 38, 39, 40},...
82
bteapot.c /* 32 patches each defined by 16 vertices, arranged in a 4 x 4 array */ /* NOTE: numbering scheme for teapot has vertices labeled from 1 to 306 */ /* remnent of the days of FORTRAN */ #include "patches.h" void display(void) { int i, j, k; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glLoadIdentity(); glTranslatef(0.0, 0.0, -10.0); glRotatef(-35.26, 1.0, 0.0, 0.0); glRotatef(-45.0, 0.0, 1.0, 0.0); /* data aligned along z axis, rotate to align with y axis */ glRotatef(-90.0, 1.0,0.0, 0.0);
83
bteapot.c for(k=0;k<32;k++) { glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &data[k][0][0][0]); for (j = 0; j <= 8; j++) { glBegin(GL_LINE_STRIP); for (i = 0; i <= 30; i++) glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0); glEnd(); glBegin(GL_LINE_STRIP); for (i = 0; i <= 30; i++) glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0); glEnd(); } glFlush(); }
84
84 Interactive Websites to try Bill Casselman's Bezier Applet http://www.math.ubc.ca/people/faculty/cass/gfx/bezier.html Wikepedia Animation http://en.wikipedia.org/wiki/Bezier_curve Edward A. Zobel's Animation http://id.mind.net/~zona/mmts/curveFitting/bezierCurves/bezierCur ve.html POV-Ray Cyclopedia Tutorial http://www.spiritone.com/~english/cyclopedia/bezier.html Andy Salter's Spline Tutorial http://www.doc.ic.ac.uk/%7Edfg/AndysSplineTutorial/index.html Evgeny Demidov's Interactive Tutorial http://ibiblio.org/e-notes/Splines/Intro.htm
85
85 Summary You can't always get what you want But if you try some time You can get what you need M. Jagger
86
86 Summary We often wish to generate curves and surfaces We would like Interpolate (include) a set of arbitrary points Easy and efficient to compute Smooth Local Control… By splicing together pieces of curves, we can attain many of these. Modern hardware and language support these curves
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.