curves in computer graphics abc · 2005-04-01 · curves in computer graphics ... o c1 continuity...

11
Parametric Curves Jason Lawrence Princeton University COS 426, Spring 2005 Curves in Computer Graphics • Fonts ABC Animation paths Shape modeling • etc… Animation (Angel, Plate 1) Shell (Douglas Turnbull, CS 426, Fall99) Implicit curves An implicit curve in the plane is expressed as: f(x, y) = 0 Example: a circle with radius r centered at origin: x 2 + y 2 -r 2 = 0 x y r Parametric curves A parametric curve in the plane is expressed as: x = f x (u) y = f y (u) Example: a circle with radius r centered at origin: x = r cos u y = r sin u x y r

Upload: others

Post on 10-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

1

Parametric Curves

Jason LawrencePrinceton University

COS 426, Spring 2005

Curves in Computer Graphics

• Fonts ABC• Animation paths

• Shape modeling

• etc…

Animation(Angel, Plate 1)

Shell(Douglas Turnbull,

CS 426, Fall99)

Implicit curvesAn implicit curve in the plane is expressed as:

f(x, y) = 0

Example: a circle with radius r centered at origin:

x2 + y2 - r2 = 0

x

y

r

Parametric curvesA parametric curve in the plane is expressed as:

x = fx(u)y = fy(u)

Example: a circle with radius r centered at origin:

x = r cos uy = r sin u

x

y

r

Page 2: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

2

Parametric curvesHow can we define arbitrary curves?

x = fx(u)y = fy(u)

Parametric curvesHow can we define arbitrary curves?

x = fx(u)y = fy(u)

Use functions that “blend” control points

x = fx(u) = V0x*(1 - u) + V1x*uy = fy(u) = V0y*(1 - u) + V1y*u

V0

V1

Parametric curvesMore generally:

x

n

ii ViuBux *)()(

0∑=

=

y

n

ii ViuBuy *)()(

0∑=

=

V0

V1

V2

V3

x(u), y(u)

Parametric curvesWhat B(u) functions should we use?

x

n

ii ViuBux *)()(

0∑=

=

y

n

ii ViuBuy *)()(

0∑=

=

Page 3: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

3

Parametric curvesWhat B(u) functions should we use?

x

n

ii ViuBux *)()(

0∑=

=

y

n

ii ViuBuy *)()(

0∑=

=

B0 B1

V0

V1

u1

1

00 1

1

00u

Parametric curvesWhat B(u) functions should we use?

x

n

ii ViuBux *)()(

0∑=

=

y

n

ii ViuBuy *)()(

0∑=

=

B0

u1

1

00

V0

V1

V2

B1

u1

1

00

B2

u1

1

00

Goals• Some attributes we might like to have:

o Interpolationo Continuityo Predictable controlo Local control

• We’ll satisfy these goals using:o Piecewiseo Parametrico Polynomials

Continuity• Parametric continuity (Cn)

o How many times differentiable is the curve at a given point

• Continuity at joints:o C0 continuity means curve is connected at jointo C1 continuity means that segments

share same first derivative at jointo Cn continuity means that segments

share same nth derivative at joint

V1

V2V3

V4

V5

V6

V0

Page 4: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

4

Parametric Polynomial Curves• Blending functions are polynomials:

• Advantages of polynomialso Easy to computeo Infinitely continuouso Easy to derive curve properties

∑=

=m

j

jji uauB

0

)(x

n

ii ViuBux *)()(

0∑=

=

y

n

ii ViuBuy *)()(

0∑=

=

V1

V2V3

V5

V6

V0

V4

Parametric Polynomial Curves• Derive polynomial Bi(u) to ensure properties

o Example: interpolation of control verticeso What about easy of control?

V1

V2V3

V5

V6

V0

Bi

u

1

0

V0 V1 V2 V3 V4 V5 V6

-1

V4

Piecewise Parametric Polynomial Curves

• Splines:o Split curve into segmentso Each segment defined by

blending subset of control vertices

• Motivation:o Provides control & efficiencyo Same blending function for every segmento Prove properties from blending functions

• Challenges o How choose blending functions?o How guarantee continuity at joints?

V1

V2V3

V5

V6

V0

V4

Piecewise Parametric Polynomial Curves

• Compute polynomial Bi(u) to ensure propertieso Example: interpolation of control vertices

and C2 continuity at joints with cubicsV1

V2V3

V5

V6

V0

Bi

u

1

0

V0 V1 V2 V3 V4 V5 V6

-1

V4

Page 5: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

5

Cubic Piecewise Parametric Polynomial Curves

• From now on, consider cubic blending functionso All ideas generalize to higher degrees

• In CAGD, higher-order functions are often usedo Hard to control wiggles

• In graphics, piecewise cubic curves will doo Smallest degree that allows C2 continuity

for arbitrary curves

Types of Splines• Splines covered in this lecture

o Hermite o Beziero Catmull-Romo B-Spline

• There are many others

Each has different blending functionsresulting in different properties

Each has different blending functionsresulting in different properties

Cubic Hermite Splines• Definition:

o Each segment defined by position and derivative attwo adjacent control vertices

o Blending functions arecubic polynomials

• Properties:o Interpolates control pointso C1 continuity at joints

V1

V2V3

V4

V5

V6

V0

Cubic Hermite Splines• Definition:

o Each segment defined by position and derivative attwo adjacent control vertices

o Blending functions arecubic polynomials

• Properties:o Interpolates control pointso C1 continuity at joints

V1

V0

P

P(u) = B0(u)*D0 + B1(u)*V0 + B2(u)* V1 + B3(u)* D1

D0

D1

Page 6: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

6

Cubic Hermite Splines

Blending functions:

∑=

=m

j

jji uauB

0

)(

Bi-1 Bi

1

1

00

Bi+1 Bi+2

1

1

00

V1

V2V3

V4

V5

V6

V0

1

1

00

1

1

00

Types of Splines• Splines covered in this lecture

o Hermite !Beziero Catmull-Romo B-Spline

• There are many others

Each has different blending functionsresulting in different properties

Each has different blending functionsresulting in different properties

Bezier curvesBlending functions:

∑=

=m

j

jji uauB

0

)(

Bi-3

1

1

00

Bi-2

1

1

00

Bi-1

1

1

00

Bi

1

1

00

V1

V2V3

V4

V5

V6

V0

Bézier curves• Developed simultaneously in 1960 by

o Bézier (at Renault) o deCasteljau (at Citroen)

• Curve Q(u) is defined by nested interpolation:

Vi’s are control points{V0, V1, …, Vn} is control polygon

V0

V1

V2

V3

Q(u)

Page 7: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

7

Basic properties of Bézier curves• Endpoint interpolation:

• Convex hull: o Curve is contained within convex hull of control polygon

• Symmetry

0)0( VQ =

nVQ =)1(

},...,{by defined )1( },...,{by defined )( 00 VVuQVVuQ nn −≡

Explicit formulation• Let’s indicate level of nesting with superscript j:

• An explicit formulation of Q(u) is given by:

• Case n=3 (expand recurrence):

11

1)1( −+

− +−= ji

ji

ji uVVuV

]......)1[(])1)[(1)[(1(

])1[(])1)[(1(

)1(

)(

02

01

01

00

12

11

11

10

21

20

30

uVVuuuVVuuu

uVVuuuVVuu

uVVu

VuQ

+−++−−−=

+−++−−=

+−=

=

More properties• General case: Bernstein polynomials

• Degree: is a polynomial of degree n

• Tangents:)()1('

)()0('

1

01

−−=−=

nn VVnQVVnQ

inin

ii uu

in

VuQ −

=

= ∑ )1( )(

0

Matrix formBézier curves may be described in matrix form:

( )

−−

−−

=

+−+−+−=

= −

=∑

3

2

1

0

23

33

22

12

03

0

0001003303631331

1

)1(3)1(3)1(

)1( )(

VVVV

uuu

VuVuuVuuVu

uuin

VuQ inin

ii

MBezier

Page 8: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

8

DisplayQ: How would you draw it using line segments?

A: Recursive subdivision!

V0

V1

V2

V3

DisplayPseudocode for displaying Bézier curves:

procedure Display({Vi}):if {Vi} flat within εthen

output line segment V0Vnelse

subdivide to produce {Li} and {Ri}Display({Li})Display({Ri})

end ifend procedure

FlatnessQ: How do you test for flatness?

A: Compare the length of the control polygonto the length of the segment between endpoints

ε+<−

−+−+− 1||

||||||

03

231201

VVVVVVVV

V0

V1

V2

V3

Splines• For more complex curves, piece together Béziers

• We want continuity across joints:o Positional (C0) continuityo Derivative (C1) continuity

• Q: How would you satisfy continuity constraints?

• Q: Why not just use higher-order Bézier curves?

• A: Splines have several of advantages:• Numerically more stable

• Easier to compute

• Fewer bumps and wiggles

Page 9: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

9

Types of Splines• Splines covered in this lecture

o Hermite o Bezier!Catmull-Romo B-Spline

• There are many others

Each has different blending functionsresulting in different properties

Each has different blending functionsresulting in different properties

Catmull-Rom splines• Properties

o Interpolate control pointso Have C0 and C1 continuity

• Derivationo Start with joints to interpolateo Build cubic Bézier between each jointo Endpoints of Bézier curves are obvious

• What should we do for the other Bézier control points?

Catmull-Rom Splines• Catmull & Rom use:

o half the magnitude of the vector between adjacent CP’s

• Many other formulations work, for example:o Use an arbitrary constant τ times this vectoro Gives a “tension” control o Could be adjusted for each joint

Properties• Catmull-Rom splines have these attributes:

o C1 continuity

o Interpolation

o Locality of control

o No convex hull property

(Proof left as an exercise.)

Page 10: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

10

Types of Splines• Splines covered in this lecture

o Hermite o Beziero Catmull-Rom!B-Spline

• There are many others

Each has different blending functionsresulting in different properties

Each has different blending functionsresulting in different properties

B-Splines• Properties:

o Local controlo C2 continuityo Cubic polynomials

• Constraints:o Three continuity conditions at each joint j

» Position of two curves same» Derivative of two curves same» Second derivatives same

o Local control» Each joint affected by 4

control vertices

• Give up interpolation :)

V1

V2V3

V5

V0

Matrix formulation for B-splines• List mathematical constraints:

• Grind through some messy math to get:

0141030303631331

61

−−

−−

=BSPLINEM

( )

=−

i

i

i

i

BSPLINEi

VVVV

MuuuuQ1

2

3

23 1)()0('')1(''

)0(')1(')0()1(

1

1

1

+

+

+

===

ii

ii

ii

QQQQ

QQ

B-Splines• Blending functions:

o Local control: how can we tell?o Interpolates control points?

u

1

0

V0 V1 V2 V3 V4 V5

V1

V2V3

V5

V0

Page 11: Curves in Computer Graphics ABC · 2005-04-01 · Curves in Computer Graphics ... o C1 continuity means that segments share same first derivative at joint o Cn continuity means that

11

Summary• Splines: mathematical way to express curves

• Motivated by “loftsman’s spline”o Long, narrow strip of wood/plastico Used to fit curves through specified data pointso Shaped by lead weights called “ducks”o Gives curves that are “smooth” or “fair”

• Have been used to design:o Automobileso Ship hullso Aircraft fuselage/wing

What’s next?• Use curves to create parameterized surfaces

• Surface of revolution

• Swept surfaces

• Surface patches

Demetri Terzopoulos Przemyslaw Prusinkiewicz