Computer...

34
Computer Graphics WS07/08 – Splines Computer Graphics - Splines - Hendrik Lensch

Transcript of Computer...

Page 1: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

Computer Graphics

- Splines -

Hendrik Lensch

Page 2: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 2

Overview• Last Time

– Image-Based Rendering

• Today– Parametric Curves– Lagrange Interpolation– Hermite Splines– Bezier Splines– DeCasteljau Algorithm– Parameterization

Page 3: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 3

Curves• Curve descriptions

– Explicit• y(x)= ± sqrt(r2 - x2), restricted domain

– Implicit:• x2 + y2 = r2 unknown solution set

– Parametric:• x(t)= r cos(t), y(t)= r sin(t), t ∈ [0, 2π]• Flexibility and ease of use

• Polynomials– Avoids complicated functions (z.B. pow, exp, sin, sqrt)– Use simple polynomials of low degree

Page 4: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 4

Parametric curves• Separate function in each coordinate

– 3D: f(t)= (x(t), y(t), z(t))

Page 5: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 5

Monomials• Monomial basis

– Simple basis: 1, t, t2, ... (t usually in [0 .. 1])• Polynomial representation

– Coefficients can be determined from a sufficient number of constraints (e.g. interpolation of given points)

• Given (n+1) parameter values ti and points Pi• Solution of a linear system in the Ai − possible, but inconvenient

• Matrix representation

( ) ∑=

==n

ii

i AttztytxtP0

)()()()(Monomials

Degree (= Order – 1)

Coefficients ∈R3

( ) [ ]⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=== −−−−

0,0,0,

1,1,1,

,,´,

1 1)()()()()(

zyx

nznynx

nznynx

nn

AAA

AAAAAA

tttTtztytxtPM

LA

Page 6: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 6

Derivatives• Derivative = tangent vector

– Polynomial of degree (n-1)

• Continuity and smoothness between parametric curves– C0 = G0 = same point– Parametric continuity C1

• Tangent vectors are identical– Geometric continuity G1

• Same direction of tangent vectors– Similar for higher derivatives

( ) [ ]⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=== −−−−

0,0,0,

1,1,1,

,,´,

11 011)´()´()´()´()´(

zyx

nznynx

nznynx

n-n

AAA

AAAAAA

)t (n-nttTtztytxtPM

LA

Page 7: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

More on Continuity• at one point:

• Geometric Continuity:– G0: curves are joined– G1: first derivatives are proportional at joint point, same direction but

not necessarily same length– G2: first and second derivatives are proportional

• Parametric Continuity:– C0: curves are joined– C1: first derivative equal– C2: first and second derivatives are equal. If t is the time, this implies

the acceleration is continuous. – Cn: all derivatives up to and including the nth are equal.

Page 8: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 8

Lagrange Interpolation• Interpolating basis functions

– Lagrange polynomials for a set of parameters T={t0, ..., tn}

• Properties– Good for interpolation at given parameter values

• At each ti: One basis function = 1, all others = 0– Polynomial of degree n (n factors linear in t)

• Lagrange Curves– Use Lagrange Polynomials with point coefficients

⎩⎨⎧ =

==−

−=∏

≠= otherwise0

1)( with ,)(

jitL

tttt

tL ijjni

n

jioj ji

jni δ

∑=

=n

ii

ni PtLtP

0

)()(

Page 9: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 9

Lagrange Interpolation• Simple Linear Interpolation

– T={t0, t1}

• Simple Quadratic Interpolation– T={t0, t1, t2}

01

011

10

110

)(

)(

tttttL

tttttL

−−

=

−−

=

t0 t1

1 L01 L1

1

20

2

10

120 )(

tttt

tttttL

−−

−−

=t0 t2

1

L01

L02t1

-1

Page 10: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 10

Problems• Problems with a single polynomial

– Degree depends on the number of interpolation constraints– Strong overshooting for high degree (n > 7)– Problems with smooth joints– Numerically unstable– No local changes

Page 11: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 11

Splines• Functions for interpolation & approximation

– Standard curve and surface primitives in geometric modeling– Key frame and in-betweens in animations– Filtering and reconstruction of images

• Historically– Name for a tool in ship building

• Flexible metal strip that tries to stay straight– Within computer graphics:

• Piecewise polynomial function

Segment 1 Segment 2 Segment 3 Segment 4

What Continuity ?

Page 12: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 12

Linear Interpolation• Hat Functions and Linear Splines

2 3 41

0 1-1

1

)(Ty )(Ty)(TP P(t) 3322 tttii +==∑ )()(1

1001

1

011

0

(t)

itTtTt

tt

t

tt

T

i −=

⎪⎪⎩

⎪⎪⎨

≥<≤<≤−−<

−+

=

2 3 41

y2y3 T(t)

Page 13: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 13

Hermite Interpolation• Hermite Basis (cubic)

– Interpolation of position P and tangent P´ informationfor t= {0, 1}

– Basis functions

233

232

231

230

)23()(

)1()(

)1()(

)21()1()(

tttH

tttH

tttH

tttH

−=

−−=

−=

+−=

0 1

30H 3

3H

32H

31H

Page 14: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 14

Hermite Interpolation• Properties of Hermite Basis Functions

– H0 (H3) interpolates smoothly from 1 to 0 (1 to 0)– H0 and H3 have zero derivative at t= 0 and t= 1

• No contribution to derivative (H1, H2)– H1 and H2 are zero at t= 0 and t= 1

• No contribution to position (H0, H3)– H1 (H2) has slope 1 at t= 0 (t= 1)

• Unit factor for specified derivative vector

• Hermite polynomials– P0, P`1 are positions ∈R3

– P`0, P1 are derivatives (tangent vectors) ∈R3

)()(´)(´)()( 331

321

310

300 tHPtHPtHPtHPtP +++=

30H 3

3H

32H

31H

Page 15: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 15

Examples: Hermite Interpolation

Page 16: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 16

Matrix Representation• Matrix representation

[ ]

[ ]

[ ]

3214444444 34444444 214444 34444 21

OL

444 3444 214444 34444 21

O44 344 21

L

ML

HH G

T

T

T

T

M

zyx

yyx

zyx

zyx

T

zyx

nznynx

nznynx

PPPP

MMMM

tt

GGGGGGGGGGGG

MMMM

tt

AAA

AAAAAA

tttP

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

= −−−

1

0

1

0

Functions Basis

21

131211

23

(4x3)G Matrix Geometry

0,0,0,

1,1,1,

2,2,2,

3,3,3,

(4x4) MMatrix Basis

21

131211

23

0,0,0,

1,1,1,

,,´,

23

´´

1

1

1)(

Page 17: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 17

Matrix Representation• For cubic Hermite interpolation we obtain:

• Solution: – Two matrices must multiply to unit matrix

HHT

HHT

HHT

HHT

P

P

P

P

GM

GM

GM

GM

)0123(´

)0100(´

)1111(

)1000(

1

0

1

0

=

=

=

=

HHH

T

T

T

T

PPPP

GMG

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

==

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

′′

0123010011111000

1

0

1

0

or

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

⎛−−−

=

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

=

000101001233

1122

0123010011111000 1

HM

Page 18: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 18

Bézier• Bézier Basis [deCasteljau´59, Bézier´62]

– Different curve representation– Start and end point– 2 point that are approximated

by the curve (cubics)– P´0= 3(b1-b0) and P´1= 3(b3-b2)

• Factor 3 due to derivative of t3

BHB

T

T

T

T

T

T

T

T

H GM

bbbb

PPPP

G =

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

3

2

1

0

1

0

1

0

3300003310000001

´´

Page 19: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 19

Basis transformation• Transformation

– P(t)=T MH GH = T MH (MHB GB) = T (MHMHB) GB = T MB GB

• Bézier Curves & Basis Functionss

– Basis functions: Bernstein polynomials

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

−−

==

0001003303631331

HBHB MMM

inini

n

i ini

ttin

tBionsBasisfunctwith

btB

=

−⎟⎟⎠

⎞⎜⎜⎝

⎛=

= ∑)1()(

)(P(t)0

33

22

12

03

3

03

13131

)(P(t)

bt-t)b(t b-t)t(b-t)(

btBi ii

+++

==∑ =

30B

B03

B13 B2

3

B33

Page 20: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 20

Properties: Bézier• Advantages:

– End point interpolation– Tangents explicitly specified– Smooth joints are simple

• P3, P4, P5 collinear G1 continuous– Geometric meaning of control points– Affine invariance

∀ ∑Bi(t) = 1– Convex hull property

• For 0<t<1: Bi(t) ≥ 0– Symmetry: Bi(t) = Bn-i(1-t)

• Disadvantages– Smooth joints need to be maintained explicitly

• Automatic in B-Splines (and NURBS)

Page 21: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 21

DeCasteljau Algorithm• Direct evaluation of the basis functions

– Simple but expensive• Use recursion

– Recursive definition of the basis functions

– Inserting this once yields:

– with the new Bézier points given by the recursion

)()1()()( 111 tBtttBtB n

ini

ni

−−− −+=

∑∑−

=

=

==1

0

11

0

0 )()()()(n

i

nii

n

i

nii tBtbtBbtP

iiki

ki

ki btbtbtttbtb =−+= −−

+ )( and )()1()()( 0111

Page 22: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 22

DeCasteljau Algorithm• DeCasteljau-Algorithm:

– Recursive degree reduction of the Bezier curve by using the recursion formula for the Bernstein polynomials

• Example:– t= 0.5

)()1()()( 111 tbtttbtb k

iki

ki

−−+ −+=

1)()()()()(1

0

11

0

0 ⋅==== ∑∑−

=

=

tbtBtbtBbtP ni

n

i

nii

n

i

nii L

Page 23: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 23

DeCasteljau Algorithm• Subdivision using the deCasteljau-Algorithm

– Take boundaries of the deCasteljau triangle as new control points for left/right portion of the curve

• Extrapolation– Backwards subdivision

• Reconstruct triangle from one side

Page 24: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 24

Catmull-Rom-Splines• Goal

– Smooth (C1)-joints between (cubic) spline segments• Algorithm

– Tangents given by neighboring points Pi-1 Pi+1– Construct (cubic) Hermite segments

• Advantage– Arbitrary number of control points– Interpolation without overshooting – Local control

Page 25: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 25

Matrix Representation• Catmull-Rom-Spline

– Piecewise polynomial curve – Four control points per segment– For n control points we obtain (n-3) polynomial segments

• Application– Smooth interpolation of a given sequence of points– Key frame animation, camera movement, etc. – Only G1-continuity– Control points should be equidistant in time

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

−−

==

+

+

+

T

T

T

T

CRCRi

i

i

i

i

PPPP

TGTtP

3

2

1

0020010114521331

21)( M __

Page 26: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 26

Choice of Parameterization• Problem

– Often only the control points are given – How to obtain a suitable parameterization ti ?

• Example: Chord-Length Parameterization

– Arbitrary up to a constant factor• Warning

– Distances are not affine invariant ! – Shape of curves changes under transformations !!

∑=

−−=

=i

jiii PPdistt

t

11

0

)(

0

Page 27: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines 27

Parameterization• Chord-Length versus uniform Parameterization

– Analog: Think P(t) as a moving object with mass that may overshoot

Uniform

Chord-Length

Page 28: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

B-Splines• Goal

– Spline curve with local control and high continuity• Given

– Degree: n– Control points: P0, ..., Pm (Control polygon, m ≥ n+1)– Knots: t0, ..., tm+n+1 (Knot vector, weakly monotonic)– The knot vector defines the parametric locations where segments join

• B-Spline Curve

– Continuity:• Cn-1 at simple knots• Cn-k at knot with multiplicity k

i

m

i

ni PtNtP ∑

=

=0

)()(

Page 29: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

B-Spline Basis Functions• Recursive Definition

)()()(

otherwise0 if1

)(

11

11

11

10

tNtt

tttNtt

tttN

ttttN

ni

ini

nini

ini

ini

iii

−+

+++

++−

+

+

−−

−−−

=

⎩⎨⎧ <<

=

0 1 2 3 4 5

0 1 2 3 4 5

N00 N1

0 N20 N3

0 N40

N01 N1

1 N21 N3

1

Uniform Knot vector

Page 30: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

B-Spline Basis Functions• Recursive Definition

– Degree increases in every step– Support increases by one knot interval

Page 31: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

B-Spline Basis Functions• Uniform Knot Vector

– All knots at integer locations• UBS: Uniform B-Spline

– Example: cubic B-Splines

• Local Support = Localized Changes– Basis functions affect only

(n+1) Spline segments– Changes are localized

ni

ni NB =

ni

ni dP =

Degree 2

Page 32: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

B-Spline Basis Functions• Convex Hull Property

– Spline segment lies in convex hull of (n+1) control points

– (n+1) control points lie on a straight line curve touches this line

– n control points coincide curve interpolates this point and is tangential to the control polygon

Degree 2

Page 33: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

Normalized Basis Functions• Basis Functions on an Interval

– Knots at beginning and end with multiplicity • NUBS: Non-uniform B-Splines

– Interpolation of end points and tangents there– Conversion to Bézier segments via knot insertion

Page 34: Computer Graphicsresources.mpi-inf.mpg.de/departments/d4/teaching/ws200708/cg/slides/CG22-Splines.pdfComputer Graphics WS07/08 – Splines 11 Splines • Functions for interpolation

Computer Graphics WS07/08 – Splines

deBoor-Algorithm• Recursive Definition of Control Points

– Evaluation at t: tl < t < tl+1: i ∈ {l-n, ..., l}• Due to local support only affected by (n+1) control points

• Properties– Affine invariance– Stable numerical evaluation

• All coefficients > 0

ii

ri

rini

riri

rini

riri

PtP

tPtt

tttPtt

tttP

=

−−

+−

−−= −

++++

+−

+++

+

)(

)()()1()(

0

11

1

1

1

ni

ni dtP =)(