Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 ›...

49
September 30, 2003 Doug James Carnegie Mellon University http://www.cs.cmu.edu/~djames/15-462/Fall03/ Parametric Representations Cubic Polynomial Forms Hermite Curves Bezier Curves and Surfaces [Angel 10.1-10.6] Parametric Representations Cubic Polynomial Forms Hermite Curves Bezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces Curves and Surfaces 15-462 Computer Graphics I Lecture 10

Transcript of Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 ›...

Page 1: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

September 30, 2003Doug JamesCarnegie Mellon University

http://www.cs.cmu.edu/~djames/15-462/Fall03/

Parametric RepresentationsCubic Polynomial FormsHermite CurvesBezier Curves and Surfaces

[Angel 10.1-10.6]

Parametric RepresentationsCubic Polynomial FormsHermite CurvesBezier Curves and Surfaces

[Angel 10.1-10.6]

Curves and SurfacesCurves and Surfaces

15-462 Computer Graphics I

Lecture 10

Page 2: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 2

GoalsGoals

• How do we draw surfaces?– Approximate with polygons– Draw polygons

• How do we specify a surface?– Explicit, implicit, parametric

• How do we approximate a surface?– Interpolation (use only points)– Hermite (use points and tangents)– Bezier (use points, and more points for tangents)

• Next lecture: splines, realization in OpenGL

Page 3: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 3

Explicit RepresentationExplicit Representation

• Curve in 2D: y = f(x)

• Curve in 3D: y = f(x), z = g(x)• Surface in 3D: z = f(x,y)• Problems:

– How about a vertical line x = c as y = f(x)?– Circle y = � (r2 – x2)1/2 two or zero values for x

• Too dependent on coordinate system• Rarely used in computer graphics

Page 4: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 4

Implicit RepresentationImplicit Representation

• Curve in 2D: f(x,y) = 0– Line: ax + by + c = 0– Circle: x2 + y2 – r2 = 0

• Surface in 3d: f(x,y,z) = 0– Plane: ax + by + cz + d = 0– Sphere: x2 + y2 + z2 – r2 = 0

• f(x,y,z) can describe 3D object:– Inside: f(x,y,z) < 0– Surface: f(x,y,z) = 0– Outside: f(x,y,z) > 0

Page 5: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 5

What Implicit Functions are Good ForWhat Implicit Functions are Good For

F < 0 ? F = 0 ? F > 0 ?

Inside/Outside Test

X

X + kV

F(X + kV) = 0

Ray - Surface Intersection Test

Page 6: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 6

Isosurfaces of Simulated TornadoIsosurfaces of Simulated Tornado

Page 7: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 7

Generate complex shapes with basic building blocks

machine an object - saw parts off, drill holes

glue pieces together

This is sensible for objects that are actually made that way (human-made, particularly machined objects)

Constructive Solid Geometry (CSG)Constructive Solid Geometry (CSG)

Page 8: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 8

A CSG TrainA CSG Train

Brian Wyvill & students, Univ. of Calgary

Page 9: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 9

•Use point-by-point boolean functions– remove a volume by using a negative object

– e.g. drill a hole by subtracting a cylinder

Subtract From

To get

Inside(BLOCK-CYL) = Inside(BLOCK) And Not(Inside(CYL))

CSG: Negative ObjectsCSG: Negative Objects

Page 10: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 10

CSGCSG

Page 11: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 11

CSGCSG

Page 12: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 12

Algebraic SurfacesAlgebraic Surfaces

• Special case of implicit representation

• f(x,y,z) is polynomial in x, y, z• Quadrics: degree of polynomial � 2

• Render more efficiently than arbitrary surfaces

• Implicit form often used in computer graphics• How do we represent curves implicitly?

Page 13: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 13

Parametric Form for CurvesParametric Form for Curves

• Curves: single parameter u (e.g. time)

• x = x(u), y = y(u), z = z(u)• Circle: x = cos(u), y = sin(u), z = 0• Tangent described by derivative

• Magnitude is “velocity”

Page 14: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 14

Parametric Form for SurfacesParametric Form for Surfaces

• Use parameters u and v

• x = x(u,v), y = y(u,v), z = z(u,v)• Describes surface as both u and v vary• Partial derivatives describe tangent plane at

each point p(u,v) = [x(u,v) y(u,v) z(u,v)]T

Page 15: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 15

Assessment of Parametric FormsAssessment of Parametric Forms

• Parameters often have natural meaning

• Easy to define and calculate– Tangent and normal– Curves segments (for example, 0 � u � 1)– Surface patches (for example, 0 � u,v � 1)

Page 16: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 16

Parametric Polynomial CurvesParametric Polynomial Curves

• Restrict x(u), y(u), z(u) to be polynomial in u

• Fix degree n

• Each ck is a column vector

Page 17: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 17

Parametric Polynomial SurfacesParametric Polynomial Surfaces

• Restrict x(u,v), y(u,v), z(u,v) to be polynomial of fixed degree n

• Each cik is a 3-element column vector• Restrict to simple case where 0 � u,v � 1

Page 18: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 18

Approximating SurfacesApproximating Surfaces

• Use parametric polynomial surfaces

• Important concepts:– Join points for segments and patches– Control points to interpolate– Tangents and smoothness– Blending functions to describe interpolation

• First curves, then surfaces

Page 19: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 19

OutlineOutline

• Parametric Representations• Cubic Polynomial Forms• Hermite Curves• Bezier Curves and Surfaces

Page 20: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 20

Cubic Polynomial FormCubic Polynomial Form

• Degree 3 appears to be a useful compromise

• Curves:

• Each ck is a column vector [ckx cky ckz]T

• From control information (points, tangents) derive 12 values ckx, cky, ckz for 0 � k � 3

• These determine cubic polynomial form• Later: how to render

Page 21: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 21

Interpolation by Cubic PolynomialsInterpolation by Cubic Polynomials

• Simplest case, although rarely used

• Curves:– Given 4 control points p0, p1, p2, p3

– All should lie on curve: 12 conditions, 12 unknowns• Space 0 � u � 1 evenly

p0 = p(0), p1 = p(1/3), p2 = p(2/3), p3 = p(1)

Page 22: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 22

Equations to Determine ckEquations to Determine ck

• Plug in values for u = 0, 1/3, 2/3, 1

Note:pk and ckare vectors!

Page 23: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 23

Interpolating Geometry MatrixInterpolating Geometry Matrix

• Invert A to obtain interpolating geometry matrix

Page 24: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 24

Joining Interpolating SegmentsJoining Interpolating Segments

• Do not solve degree n for n points

• Divide into overlap sequences of 4 points• p0, p1, p2, p3 then p3, p4, p5, p6, etc.

• At join points– Will be continuous (C0 continuity)– Derivatives will usually not match (no C1 continuity)

Page 25: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 25

Blending FunctionsBlending Functions

• Make explicit, how control points contribute

• Simplest example: straight line with control points p0 and p3

• p(u) = (1 – u) p0 + u p3

• b0(u) = 1 – u, b3(u) = u

1

1b3(u)

b0(u)

u

Page 26: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 26

Blending Polynomials for InterpolationBlending Polynomials for Interpolation

• Each blending polynomial is a cubic

• Solve (see [Angel, p. 427]):

Page 27: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 27

Cubic Interpolation PatchCubic Interpolation Patch

• Bicubic surface patch with 4 � 4 control points

Note: each cik is3 column vector(48 unknowns)

[Angel, Ch. 10.4.2]

Page 28: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 28

OutlineOutline

• Parametric Representations• Cubic Polynomial Forms• Hermite Curves• Bezier Curves and Surfaces

Page 29: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 29

Hermite CurvesHermite Curves

• Another cubic polynomial curve

• Specify two endpoints and their tangents

Page 30: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 30

Deriving the Hermite FormDeriving the Hermite Form

• As before

• Calculate derivative

• Yields

Page 31: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 31

Summary of Hermite EquationsSummary of Hermite Equations

• Write in matrix form

• Remember pk and p’k and ck are vectors!

• Let q = [p0 p3 p’0 p’3]T and invert to find Hermite geometry matrix MH satisfying

Page 32: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 32

Blending FunctionsBlending Functions

• Explicit Hermite geometry matrix

• Blending functions for u = [1 u u2 u3]T

Page 33: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 33

Join Points for Hermite CurvesJoin Points for Hermite Curves

• Match points and tangents (derivatives)

• Much smoother than point interpolation• How to obtain the tangents?

• Skip Hermite surface patch• More widely used: Bezier curves and surfaces

Page 34: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 34

Parametric ContinuityParametric Continuity

• Matching endpoints (C0 parametric continuity)

• Matching derivatives (C1 parametric continuity)

Page 35: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 35

Geometric ContinuityGeometric Continuity

• For matching tangents, less is required

• G1 geometric continuity• Extends to higher derivatives

Page 36: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 36

OutlineOutline

• Parametric Representations• Cubic Polynomial Forms• Hermite Curves• Bezier Curves and Surfaces

Page 37: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 37

Bezier CurvesBezier Curves

• Widely used in computer graphics

• Approximate tangents by using control points

Page 38: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 38

Equations for Bezier CurvesEquations for Bezier Curves

• Set up equations for cubic parametric curve

• Recall:

• Solve for ck

Page 39: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 39

Bezier Geometry MatrixBezier Geometry Matrix

• Calculate Bezier geometry matrix MB

• Have C0 continuity, not C1 continuity• Have C1 continuity with additional condition

Page 40: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 40

Blending PolynomialsBlending Polynomials

• Determine contribution of each control point

Smooth blendingpolynomials

Page 41: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 41

Convex Hull PropertyConvex Hull Property

• Bezier curve contained entirely in convex hull of control points

• Determined choice of tangent coefficient (?)

Page 42: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 42

Bezier Surface PatchesBezier Surface Patches

• Specify Bezier patch with 4 � 4 control points

• Bezier curves along the boundary

Page 43: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 43

TwistTwist

• Inner points determine twist at corner

• Flat means p00, p10, p01, p11 in one plane

• (∂2p/∂u∂v)(0,0) = 0

Page 44: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 44

The Utah TeapotThe Utah Teapot

Page 45: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 45

The Utah TeapotThe Utah Teapot

See http://www.sjbaker.org/teapot/

for more history.

The Six Platonic Solids(by Jim Arvo and Dave Kirk, from their '87 SIGGRAPH paper Fast Ray Tracing by Ray Classification.)

Page 46: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 46

The Utah TeapotThe Utah Teapot

Page 47: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 47

The teapotis just cubic Bezierpatches!

The teapotis just cubic Bezierpatches!

Page 48: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 48

SummarySummary

• Parametric Representations• Cubic Polynomial Forms• Hermite Curves• Bezier Curves and Surfaces

Page 49: Curves and Surfaces - Carnegie Mellon School of Computer ... › ~djames › 15-462 › Fall03 › notes › 10-curves.pdfBezier Curves and Surfaces [Angel 10.1-10.6] Curves and Surfaces

9/30/2003 15-462 Graphics I 49

PreviewPreview

• B-Splines: more continuity (C2)

• Non-uniform B-splines (“heavier” points)• Non-uniform rational B-splines (NURBS)

– Rational functions instead of polynomials– Based on homogeneous coordinates

• Rendering and recursive subdivision

• Curves and surfaces in OpenGL