<<

- Splines -

Hendrik Lensch

Computer Graphics WS07/08 – Splines Overview • Last Time – Image-Based Rendering

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

Computer Graphics WS07/08 – Splines 2 Curves • 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 • – Avoids complicated functions (z.B. pow, exp, sin, sqrt) – Use simple polynomials of low degree

Computer Graphics WS07/08 – Splines 3 Parametric curves • Separate in each coordinate – 3D: f(t)= (x(t), y(t), z(t))

Computer Graphics WS07/08 – Splines 4 Monomials • Monomial – Simple basis: 1, t, t2, ... (t usually in [0 .. 1]) • representation Degree (= Order – 1) n i Coefficients ∈R3 P(t) = ()x(t) y(t) z(t) = ∑t Ai i=0 Monomials – 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

⎡ Ax,n A´y,n Az,n ⎤ ⎢A A A ⎥ n n−1 ⎢ x,n−1 y,n−1 z,n−1 ⎥ P(t) = ()x(t) y(t) z(t) = T (t) A = []t t L 1 ⎢ M ⎥ ⎢ ⎥ ⎣⎢ Ax,0 Ay,0 Az,0 ⎦⎥

Computer Graphics WS07/08 – Splines 5 Derivatives • Derivative = tangent vector – Polynomial of degree (n-1)

⎡ Ax,n A´y,n Az,n ⎤ ⎢A A A ⎥ n−1 n-1 ⎢ x,n−1 y,n−1 z,n−1 ⎥ P´(t) = ()x´(t) y´(t) z´(t) = T´(t) A = []nt (n-1)t L 1 0 ⎢ M ⎥ ⎢ ⎥ ⎣⎢ Ax,0 Ay,0 Az,0 ⎦⎥

• 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

Computer Graphics WS07/08 – Splines 6 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.

Computer Graphics WS07/08 – Splines Lagrange Interpolation • Interpolating basis functions

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

n n t − t j n ⎧1 i = j Li (t) = ∏ , with Li (t j ) = δij = ⎨ j=o ti − t j ⎩0 otherwise i≠ j • 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 n n P(t) = ∑ Li (t)Pi i=0

Computer Graphics WS07/08 – Splines 8 Lagrange Interpolation • Simple Linear Interpolation

–T={t0, t1} t − t 1 1 1 L 1 L 1 L0 (t) = 0 1 t0 − t1

1 t − t0 L1(t) = t1 − t0 t t • Simple Quadratic Interpolation0 1

–T={t0, t1, t2} 1

2 t − t1 t − t2 L0 (t) = 2 t0 − t1 t0 − t2 t0 t1 L0 t2 1 L0 -1

Computer Graphics WS07/08 – Splines 9 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

Computer Graphics WS07/08 – Splines 10 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

What Continuity ?

Segment 1 Segment 2 Segment 3 Segment 4

Computer Graphics WS07/08 – Splines 11 Linear Interpolation • Hat Functions and Linear Splines

1 y2 y3 T(t)

-1 01 1 234

⎧ 0 t < −1 ⎪ ⎪1+ t −1≤ t < 0 T(t) = ⎨ ⎪1− t 0 ≤ t <1 1 234 ⎩⎪ 0 t ≥1

P(t) = ∑ PiTi (t) = y2T2 (t) + y3T3 (t) Ti (t) = T(t − i)

Computer Graphics WS07/08 – Splines 12 Hermite Interpolation • Hermite Basis (cubic) – Interpolation of position P and tangent P´ information for t= {0, 1}

3 H3 H0 3 01 – Basis functions

3 2 H0 (t) = (1− t) (1+ 2t) 3 H1 3 2 H1 (t) = t(1− t) 3 2 H 2 (t) = −t (1− t) 3 H2 3 2 H3 (t) = (3− 2t)t

Computer Graphics WS07/08 – Splines 13 Hermite Interpolation • Properties of Hermite Basis Functions

–H0 (H3) interpolates smoothly from 1 to 0 (1 to 0) –Hand H have zero derivative at t= 0 and t= 1 3 H3 0 3 H0 3 • No contribution to derivative (H1, H2) –H1 and H2 are zero at t= 0 and t= 1 • No contribution to position (H , H ) 0 3 3 H1 –H1 (H2) has slope 1 at t= 0 (t= 1) • Unit factor for specified derivative vector H3 • Hermite polynomials 2 3 –P0, P`1 are positions ∈R 3 –P`0, P1 are derivatives (tangent vectors) ∈R

3 3 3 3 P(t) = P0 H 0 (t) + P0´H1 (t) + P1´H 2 (t) + P1H3 (t)

Computer Graphics WS07/08 – Splines 14 Examples: Hermite Interpolation

Computer Graphics WS07/08 – Splines 15 Matrix Representation • Matrix representation

⎡ Ax,n A´y,n Az,n ⎤ ⎢A A A ⎥ 3 2 ⎢ x,n−1 y,n−1 z,n−1 ⎥ P(t) = []t t L 1 = ⎢ M ⎥ ⎢ ⎥ ⎣⎢ Ax,0 Ay,0 Az,0 ⎦⎥ [] ⎡M11 M12 M13 ⎤ ⎡Gx,3 Gy,3 Gz,3 ⎤ ⎢ ⎥ ⎢M ⎥ G G G 3 2 ⎢ 21 O ⎥ ⎢ x,2 y,2 z,2 ⎥ t t L 1 = 1424 434 ⎢ ⎥ ⎢Gx,1 Gy,1 Gy,1 ⎥ []T ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ ⎣⎢Gx,0 Gy,0 Gz,0 ⎦⎥ 142444 43444 14244 4344 Basis Matrix M (4x4) Geometry Matrix G (4x3) T ⎡M11 M12 M13 ⎤⎡ P0 ⎤ ⎢ ⎥⎢ T ⎥ M P t 3 t 2 1 ⎢ 21 O ⎥⎢ 1 ⎥ L ⎢ T ⎥ ⎢ ⎥ P´0 ⎢ ⎥⎢ T ⎥ ⎣ ⎦⎣⎢P´1 ⎦⎥ 142444 43444 123 M G 142444444 4344H 4444 H Basis Functions

Computer Graphics WS07/08 – Splines 16 Matrix Representation • For cubic Hermite interpolation we obtain: PT = (0 0 0 1)M G ⎛ PT ⎞ ⎛0 0 0 1⎞ 0 H H ⎜ 0 ⎟ ⎜ ⎟ T T P1 = (1 1 1 1)M H G H ⎜ P ⎟ ⎜1 1 1 1⎟ or 1 = G = M G P´T = (0 0 1 0)M G ⎜ P′T ⎟ H ⎜0 0 1 0⎟ H H 0 H H ⎜ 0 ⎟ ⎜ ⎟ P´T = (3 2 1 0)M G ⎜ T ⎟ ⎜ ⎟ 1 H H ⎝ P1′ ⎠ ⎝3 2 1 0⎠ • Solution: – Two matrices must multiply to unit matrix

−1 ⎛0 0 0 1⎞ ⎛ 2 − 2 1 1 ⎞ ⎜ ⎟ ⎜ ⎟ ⎜1 1 1 1⎟ ⎜− 3 3 − 2 −1⎟ M = = H ⎜0 0 1 0⎟ ⎜ 0 0 1 0 ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎝3 2 1 0⎠ ⎝ 1 0 0 0 ⎠

Computer Graphics WS07/08 – Splines 17 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

T T ⎡ P0 ⎤ ⎡ 1 0 0 0⎤⎡b0 ⎤ ⎢ T ⎥ ⎢ ⎥⎢ T ⎥ P 0 0 0 1 b G = ⎢ 1 ⎥ = ⎢ ⎥⎢ 1 ⎥ = M G H ⎢P´ T ⎥ ⎢− 3 3 0 0⎥⎢bT ⎥ HB B ⎢ 0 ⎥ ⎢ ⎥⎢ 2 ⎥ T 0 0 − 3 3 T ⎣⎢P´1 ⎦⎥ ⎣ ⎦⎣⎢b3 ⎦⎥

Computer Graphics WS07/08 – Splines 18 Basis transformation • Transformation

– P(t)=T MH GH = T MH (MHB GB) = T (MHMHB) GB = T MB GB ⎡−1 3 − 3 1⎤ 3 B0 ⎢ 3 − 6 3 0⎥ M = M M = ⎢ ⎥ B H HB ⎢− 3 3 0 0⎥ ⎢ ⎥ 3 ⎣ 1 0 0 0⎦ B3 B3 • Bézier Curves & Basis Functionss 0 3 3 3 B B P(t) = B3 (t)b = 1 2 ∑i=0 i i 3 2 2 3 (1-t) b0 + 3t(1-t) b1 + 3t (1-t)b2 + t b3 n P(t) = B n (t)b ∑i=0 i i

n ⎛n⎞ i n−i with Basisfunctions Bi (t) = ⎜ ⎟t (1− t) ⎝ i ⎠ – Basis functions: Bernstein polynomials

Computer Graphics WS07/08 – Splines 19 Properties: Bézier • Advantages: – End point interpolation – Tangents explicitly specified – Smooth joints are simple 1 •P3, P4, P5 collinear Æ G continuous – Geometric meaning of control points – Affine invariance

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

• For 0

Computer Graphics WS07/08 – Splines 20 DeCasteljau Algorithm • Direct evaluation of the basis functions – Simple but expensive • Use recursion – Recursive definition of the basis functions n n−1 n−1 Bi (t) = tBi−1 (t) + (1− t)Bi (t) – Inserting this once yields: n n−1 0 n 1 n−1 P(t) = ∑bi Bi (t) = ∑bi (t)Bi (t) i=0 i=0 – with the new Bézier points given by the recursion

k k −1 k −1 0 bi (t) = tbi+1 (t) + (1− t)bi (t) and bi (t) = bi

Computer Graphics WS07/08 – Splines 21 DeCasteljau Algorithm • DeCasteljau-Algorithm: – Recursive degree reduction of the Bezier curve by using the recursion formula for the Bernstein polynomials n n−1 0 n 1 n−1 n P(t) = ∑bi Bi (t) = ∑bi (t)Bi (t) = L = bi (t)⋅1 i=0 i=0 k k −1 k −1 bi (t) = tbi+1 (t) + (1− t)bi (t) • Example: –t= 0.5

Computer Graphics WS07/08 – Splines 22 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

Computer Graphics WS07/08 – Splines 23 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

Computer Graphics WS07/08 – Splines 24 Matrix Representation • Catmull-Rom-Spline – Piecewise polynomial curve – Four control points per segment – For n control points we obtain (n-3) polynomial segments ⎡−1 3 − 3 1⎤⎡ PT ⎤ ⎢ i ⎥ ⎢ 2 − 5 4 1⎥ PT i 1 ⎢ i+1 ⎥ P (t) = TM G = T ⎢ __ ⎥ CR CR 2 ⎢−1 0 1 0⎥⎢PT ⎥ i+2 ⎢ ⎥⎢ T ⎥ ⎣ 0 2 0 0⎦⎢P ⎥ • Application ⎣ i+3 ⎦ – Smooth interpolation of a given sequence of points – Key frame animation, camera movement, etc. –Only G1-continuity – Control points should be equidistant in time

Computer Graphics WS07/08 – Splines 25 Choice of Parameterization • Problem – Often only the control points are given

– How to obtain a suitable parameterization ti ? • Example: Chord-Length Parameterization

t0 = 0 i ti = ∑ dist(Pi − Pi−1) j=1 – Arbitrary up to a constant factor • Warning – Distances are not affine invariant ! – Shape of curves changes under transformations !!

Computer Graphics WS07/08 – Splines 26 Parameterization • Chord-Length versus uniform Parameterization – Analog: Think P(t) as a moving object with mass that may overshoot

Uniform

Chord-Length

Computer Graphics WS07/08 – Splines 27 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

m n P(t) = ∑ Ni (t)Pi i=0 – Continuity:

•Cn-1 at simple knots

•Cn-k at knot with multiplicity k

Computer Graphics WS07/08 – Splines B-Spline Basis Functions • Recursive Definition

0 ⎧1 if ti < t < ti+1 Ni (t) = ⎨ ⎩0 otherwise

n t − ti n−1 t − ti+n+1 n−1 Ni (t) = Ni (t) − Ni+1 (t) ti+n − ti ti+n+1 − ti+1

N 0 0 0 0 0 0 N1 N2 N3 N4

0 1 2 3 4 5 Uniform Knot vector

N 1 1 1 1 0 N1 N2 N3

0 1 2 3 4 5

Computer Graphics WS07/08 – Splines B-Spline Basis Functions • Recursive Definition – Degree increases in every step – Support increases by one knot interval

Computer Graphics WS07/08 – Splines B-Spline Basis Functions • Uniform Knot Vector – All knots at integer locations • UBS: Uniform B-Spline

n n – Example: cubic B-Splines Bi = Ni

• Local Support = Localized Changes – Basis functions affect only (n+1) Spline segments – Changes are localized

n n Pi = di

Degree 2

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 Î Degree 2 curve touches this line – n control points coincide Î curve interpolates this point and is tangential to the control polygon

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

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

r t − ti+r r−1 t − ti+r r−1 Pi (t) = (1− )Pi (t) + Pi+1 (t) ti+n+1 − ti+r ti+n+1 − ti+r 0 Pi (t) = Pi • Properties – Affine invariance – Stable numerical evaluation • All coefficients > 0

n n Pi (t) = di

Computer Graphics WS07/08 – Splines