1 Bezier Curves and Surfaces © Jeff Parker, Nov 2011.

Slides:



Advertisements
Similar presentations
Lecture Notes #11 Curves and Surfaces II
Advertisements

Lecture 10 Curves and Surfaces I
Advanced Computer Graphics (Spring 2005) COMS 4162, Lecture 13: NURBs, Spline Surfaces Ravi Ramamoorthi Some material.
Cubic Curves CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2006.
ICS 415 Computer Graphics Bézier Splines (Chapter 8)
CS 445/645 Fall 2001 Hermite and Bézier Splines. Specifying Curves Control Points –A set of points that influence the curve’s shape Knots –Control points.
© University of Wisconsin, CS559 Spring 2004
Jehee Lee Seoul National University
B-Spline Blending Functions
Dr. S.M. Malaek Assistant: M. Younesi
1 Curves and Surfaces. 2 Representation of Curves & Surfaces Polygon Meshes Parametric Cubic Curves Parametric Bi-Cubic Surfaces Quadric Surfaces Specialized.
Lecture 29 of 42 Bezier Curves and Splines Wednesday, 02 April 2008
Splines II – Interpolating Curves
Informationsteknologi Monday, December 10, 2007Computer Graphics - Class 161 Today’s class Curve fitting Evaluators Surfaces.
Advanced Computer Graphics (Spring 2005) COMS 4162, Lecture 12: Spline Curves (review) Ravi Ramamoorthi Most material.
1 Lecture 13 Modeling Curved Lines and Surfaces. 2 Types of Surfaces Ruled Surfaces B-Splines and Bezier Curves Surfaces of Revolution.
Designing Parametric Cubic Curves Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Geometric Modeling Surfaces Mortenson Chapter 6 and Angel Chapter 9.
Curves Mortenson Chapter 2-5 and Angel Chapter 9
Bezier and Spline Curves and Surfaces Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Modelling: Curves Week 11, Wed Mar 23
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Curves Week 13, Mon 24 Nov 2003.
Bezier and Spline Curves and Surfaces CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
COEN Computer Graphics I
Chapter 10: Curves and Surfaces Part 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Designing Parametric Cubic Curves
Curve Surfaces June 4, Examples of Curve Surfaces Spheres The body of a car Almost everything in nature.
Splines III – Bézier Curves
Curve Modeling Bézier Curves
Bresenham’s Algorithm. Line Drawing Reference: Edward Angel’s book: –6 th Ed. Sections 6.8 and 6.9 Assuming: –Clipped (to fall within the window) –2D.
11/19/02 (c) 2002, University of Wisconsin, CS 559 Last Time Many, many modeling techniques –Polygon meshes –Parametric instancing –Hierarchical modeling.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
A D V A N C E D C O M P U T E R G R A P H I C S CMSC 635 January 15, 2013 Spline curves 1/23 Curves and Surfaces.
Interactive Graphics Lecture 9: Slide 1 Interactive Graphics Lecture 9: Introduction to Spline Curves.
(Spline, Bezier, B-Spline)
V. Space Curves Types of curves Explicit Implicit Parametric.
1 Bezier Curves © Jeff Parker, Nov Goal We often wish to draw generate curves Through selection of arbitrary points Smooth (many derivatives)
Introduction to Computer Graphics with WebGL
CS 445 / 645 Introduction to Computer Graphics Lecture 23 Bézier Curves Lecture 23 Bézier Curves.
Picking and Curves Week 6 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico CS 480/680.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Parametric Curves.
Curves and Surfaces Chapter 10. CS 480/680 2Chapter 9 -- Hierarchical Models Introduction: Introduction: Until now we have worked with flat entities such.
Splines IV – B-spline Curves based on: Michael Gleicher: Curves, chapter 15 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides.
Parametric Surfaces Define points on the surface in terms of two parameters Simplest case: bilinear interpolation s t s x(s,t)x(s,t) P 0,0 P 1,0 P 1,1.
1 Bezier Curves and Surfaces © Jeff Parker, Nov 2009.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS Representation of Curves and Surfaces Graphics.
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
04/18/02(c) 2002 University of Wisconsin Last Time Hermite Curves Bezier Curves.
Curves: ch 4 of McConnell General problem with constructing curves: how to create curves that are “smooth” CAD problem Curves could be composed of segments.
Rendering Curves and Surfaces Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Angel:
Greg Humphreys CS445: Intro Graphics University of Virginia, Fall 2003 Parametric Curves & Surfaces Greg Humphreys University of Virginia CS 445, Spring.
11/26/02(C) University of Wisconsin Last Time BSplines.
CSCE 441: Keyframe Animation/Smooth Curves (Cont.) Jinxiang Chai.
CSCE 441: Keyframe Animation/Smooth Curves (Cont.) Jinxiang Chai.
Designing Parametric Cubic Curves 1. 2 Objectives Introduce types of curves ­Interpolating ­Hermite ­Bezier ­B-spline Analyze their performance.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 34 Curves and Surfaces III.
CSCI480/582 Lecture 10 Chap.2.3 Cubic Splines – B-Splines and NURBS Feb, 13, 2009.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Splines Sang Il Park Sejong University. Particle Motion A curve in 3-dimensional space World coordinates.
Rendering Bezier Curves (1) Evaluate the curve at a fixed set of parameter values and join the points with straight lines Advantage: Very simple Disadvantages:
Curves University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
Introduction to Parametric Curve and Surface Modeling.
© University of Wisconsin, CS559 Spring 2004
CS5500 Computer Graphics May 11, 2006
© University of Wisconsin, CS559 Spring 2004
UNIT-5 Curves and Surfaces.
CSCE 441: Keyframe Animation/Smooth Curves (Cont.)
Introduction to Parametric Curve and Surface Modeling
Presentation transcript:

1 Bezier Curves and Surfaces © Jeff Parker, Nov 2011

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

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 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

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 Runge Phenomena Try to approximate the red curve with polynomials Interpolate (hit curve) at evenly spaced x values

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

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 Terminology Interpolation vs. Approximation

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

Parametric Functions We will be exploring Parametric Curves Parametric Surfaces are similar Natural parameterization Moves with curve length

Sample Surface Parametric map the unit square to the sphere

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

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

Piece these together Piece together a curve that connects a set of points p1p1 p2p2 p3p3 p4p4 p0p0

Piece these together Piece together a curve that connects a set of points p1p1 p2p2 p3p3 p4p4 p0p0

Piece these together Create series of equations p1p1 p2p2 p0p0 p3p3 p4p4 p1p1 p2p2 p3p3 p4p4 p0p0 Blending Functions

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

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

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

Terminology Not continuous at break Not differentiable at corner Next: C(1) vs G(1)

Geometric Continuity

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 Bezier Animation zierCurves/bca2/Bezier1Animation2.html

25 Note rate of movement

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 De Casteljau Algorithm Compute points on the curve without evaluating polynomials Can use the midpoints, so only need to shift right

28 De Casteljau's Method Compute points on the curve without evaluating polynomials Can use the midpoints, so only need to shift right

29 De Casteljau's Method Gives simple recursive method to draw curve Keep dividing until each subpiece of the curve is almost straight

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 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

De Casteljau Let's spell out what this means Notation differs from figure

Expand one level Derivation is similar

Find third level

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 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

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 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)

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 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 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

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?

Review: Blending function for line We know p 0 and p 1. We want vectors a 0 and a 1 so that

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

We know p, wish to find a To solve for p, can invert the Constraint Matrix, C to find the Blending Matrix, B

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

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

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

Constraint Matrix for Bezier Now we have a constraint matrix C: find it’s inverse B

Apply Constraint Matrix Apply the vector [1 u u 2 u 3 ] to matrix B

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

Derive the values a i Another way to look at this:

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

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…

North and south pole and point at (Eastern) infinity We only need a quadratic Bezier for 3 points Quadratic Bezier

But are these points on the unit circle? x y

The control points are weighted This gives NURBS more degrees of freedom Degree Elevation

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

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 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 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 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 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 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

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)

Hermite Polynomial

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 Splines Approximate rather than interpolate (blue vs red curves) (Image is of a traditional spline used in boat building)

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 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 Blending Functions convex hull property E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

73 Basis Functions In terms of the blending polynomials E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012

Basis Functions

75 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison- Wesley 2012 B-Spline Patches defined over only 1/9 of region

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 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 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)

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();

Teapot

bteapot.c // vertices.h GLfloat vertices[306][3]={{1.4, 0.0, 2.4}, {1.4, , 2.4}, {0.784, -1.4, 2.4}, {0.0, -1.4, 2.4}, {1.3375, 0.0, }, {1.3375, , }, {0.749, , }, {0.0, , }, {1.4375, 0.0, }, {1.4375, , }, {0.805, , },... // 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},...

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);

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 Interactive Websites to try Bill Casselman's Bezier Applet Wikepedia Animation Edward A. Zobel's Animation ve.html POV-Ray Cyclopedia Tutorial Andy Salter's Spline Tutorial Evgeny Demidov's Interactive Tutorial

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 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