cs 543: computer graphics lecture 10 (part iii):...

26
CS 543: Computer Graphics Lecture 10 (Part III): Curves Emmanuel Agu

Upload: others

Post on 26-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

CS 543: Computer GraphicsLecture 10 (Part III): Curves

Emmanuel Agu

Page 2: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

So Far…

n Dealt with straight lines and flat surfacesn Real world objects include curvesn Need to develop:

n Representations of curvesn Tools to render curves

Page 3: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Curve Representation: Explicit

n One variable expressed in terms of anothern Example:

n Works if one x-value for each y valuen Example: does not work for a sphere

n Rarely used in CG because of this limitation

),( yxfz =

22 yxz +=

Page 4: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Curve Representation: Implicit

n Algebraic: represent 2D curve or 3D surface as zeros of a formula

n Example: sphere representation

n May restrict classes of functions usedn Polynomial: function which can be expressed as linear

combination of integer powers of x, y, zn Degree of algebraic function: highest sum of powers in

functionn Example: yx4 has degree of 5

01222 =−++ zyx

Page 5: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Curve Representation: Parametric

n Represent 2D curve as 2 functions, 1 parameter

n 3D surface as 3 functions, 2 parameters

n Example: parametric sphere

))(),(( uyux

)),(),,(),,(( vuzvuyvux

φφθθφφθθφφθ

sin),(sincos),(coscos),(

===

zyx

Page 6: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Choosing Representations

n Different representation suitable for different applicationsn Implicit representations good for:

n Computing ray intersection with surfacen Determining if point is inside/outside a surface

n Parametric representation good for:n Breaking surface into small polygonal elements for renderingn Subdivide into smaller patches

n Sometimes possible to convert one representation into another

Page 7: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Continuity

n Consider parametric curve

n We would like smoothest curves possiblen Mathematically express smoothness as continuity (no jumps)n Defn: if kth derivatives exist, and are continuous, curve has

kth order parametric continuity denoted Ck

TuzuyuxuP ))(),(),(()( =

Page 8: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Continuity

n 0th order means curve is continuousn 1st order means curve tangent vectors vary continuously, etcn We generally want highest continuity possiblen However, higher continuity = higher computational costn C2 is usually acceptable

Page 9: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Interactive Curve Design

n Mathematical formula unsuitable for designersn Prefer to interactively give sequence of control points n Write procedure:

n Input: sequence of pointsn Output: parametric representation of curve

Page 10: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Interactive Curve Design

n 1 approach: curves pass through control points (interpolate)n Example: Lagrangian Interpolating Polynomialn Difficulty with this approach:

n Polynomials always have “wiggles”n For straight lines wiggling is a problem

n Our approach: merely approximate control points (Bezier, B-Splines)

Page 11: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Consider smooth curve that approximates sequence of control points [p0,p1,….]

n Blending functions: u and (1 – u) are non-negative and sum to one

10)1()( uppuup +−= 10 ≤≤ u

Page 12: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Now consider 3 pointsn 2 line segments, P0 to P1 and P1 to P2

1001 )1()( uppuup +−= 2111 )1()( uppuup +−=

Page 13: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

)()1()( 1101 uuppuup +−=

22

102 ))1(2()1( pupuupu +−+−=

Example: Bezier curves with 3, 4 control points

Page 14: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

202 )1()( uub −=

Blending functions for degree 2 Bezier curve

)1(2)(12 uuub −= 222 )( uub =

Note: blending functions, non-negative, sum to 1

Page 15: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Extend to 4 points P0, P1, P2, P3

n Repeated interpolation is De Casteljau algorithmn Final result above is Bezier curve of degree 3

32

21

20

3 ))1(3()1(3()1()( upuupuupuup +−+−+−=

Page 16: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Blending functions for 4 pointsn These polynomial functions called Bernstein’s polynomials

333

223

213

303

)(

)1(3)(

)1(3)(

)1()(

uub

uuub

uuub

uub

=

−=

−=

−=

Page 17: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Writing coefficient of blending functions gives Pascal’s triangle

1

4

1

1

1

1

1

2

4

3

6

1 3

1

1

In general, blending function for k Bezier curve has form

iikik uu

ik

ub −−

= )1()( )!(!

!iki

kik

−=

where

Page 18: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

De Casteljau Algorithm

n Can express cubic parametric curve in matrix form

=

3

2

1

0

32 ],,,1[)(

pppp

Muuuup B

where

−−−

−=

13310363

00330001

BM

Page 19: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Subdividing Bezier Curves

n OpenGL renders flat objects n To render curves, approximate by small linear segmentsn Subdivide curved surface to polygonal patchesn Bezier curves useful for elegant, recursive subdivisionn May have different levels of recursion for different parts of

curve or surfacen Example: may subdivide visible surfaces more than hidden

surfaces

Page 20: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Subdividing Bezier Curves

n Let (P0… P3) denote original sequence of control pointsn Relabel these points as (P00…. P30)n Repeat interpolation (u = ½) and label vertices as below n Sequences (P00,P01,P02,P03) and (P03,P12,P21,30)

define Bezier curves alson Bezier Curves can either be straightened or curved

recursively in this way

Page 21: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Bezier Surfaces

n Bezier surfaces: interpolate in two dimensionsn This called Bilinear interpolationn Example: 4 control points, P00, P01, P10, P11, 2

parameters u and vn Interpolate between

n P00 and P01 using un P10 and P11 using un Repeat two steps above using v

))1(())1)((1(),( 11100100 uppuvuppuvvup +−++−−=

11100100 )1()1()1)(1( vuppuvupvpuv +−+−+−−=

Page 22: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

Bezier Surfaces

n Recalling, (1-u) and u are first-degree Bezier blending functions b0,1(u) and b1,1(u)

11111101011101000101 )()()()()()(),( pubvbpubbvbpubvbvup ++=

Generalizing for cubic ∑∑= =

=3

0

3

0,3,3, )()(),(

i jjiji pubvbvup

Rendering Bezier patches in openGL: v=u = 1/2

Page 23: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

B-Splines

n Bezier curves are elegant but too many control pointsn Smoother = more control points = higher order polynomialn Undesirable: every control point contributes to all parts of curven B-splines designed to address Bezier shortcomingsn Smooth blending functions, each non-zero over small rangen Use different polynomial in each range, (piecewise

polynomial) ∑=

=m

iii puBup

0

)()(

B-spline blending functions, order 2

Page 24: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

NURBS

n Encompasses both Bezier curves/surfaces and B-splinesn Non-uniform Rational B-splines (NURBS)n Rational function is ratio of two polynomialsn NURBS use rational blending functionsn Some curves can be expressed as rational functions but

not as simple polynomialsn No known exact polynomial for circlen Rational parametrization of unit circle on xy-plane:

0)(1

2)(

11

)(

2

2

2

=+

=

+−

=

uzuu

uy

uu

ux

Page 25: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

NURBS

n We can apply homogeneous coordinates to bring in w

n Using w, we cleanly integrate rational parametrizationn Useful property of NURBS: preserved under transformationn Thus, we can project control points and then render NURBS

2

2

1)(

0)(2)(1)(

uuw

uzuuy

uux

+=

==

−=

Page 26: CS 543: Computer Graphics Lecture 10 (Part III): Curvesweb.cs.wpi.edu/~emmanuel/courses/cs543/slides/lecture10_p3.pdfB-Splines n Bezier curves are elegant but too many control points

References

n Hill, chapter 11