Computer Graphics - Splines - Arsène Pérard-Gayot (Slides by Piotr Danilewski)
CURVES
Curves Explicit y = f x f: R R γ = x, f x y = 1 x 2 Implicit F x, y = 0 F: R 2 R γ = x, y : F x, y = 0 x 2 + y 2 = 0 Parametric f x t f t f y t f x, f y : R R f: R R 2 typically: t 0,1 γ = x, y : t R: f x t = x f y t = y x t = cos t y t = sin t t 0,2π
Polynomial curves Avoids complicated functions (e.g. pow, exp, sin, sqrt) Use simple polynomials of low degree Flexible, easy to use x t = a 0 + a 1 t + a 2 t 2 + a 3 t 3 + y t = b 0 + b 1 t + b 2 t 2 + b 3 t 3 + z t = c 0 + c 1 t + c 2 t 2 + c 3 t 3 + monomial degree P t = x t y t z t = n i=0 t i a i, b i, c i monomial basis P t = t n t n 1 1 a n b n c n a n 1 b n 1 c n 1 a 0 b 0 c 0 Coefficients R 3 n coordinates each coordinate is R 3
Derivatives angent vector P t = t n t n 1 t 1 a n b n c n a n 1 b n 1 c n 1 a 0 b 0 c 0 P t = nt n 1 n 1 t n 1 1 0 a n b n c n a n 1 b n 1 c n 1 a 0 b 0 c 0
Continuity Continuity and smoothness between parametric curves γ 1, γ 2 : [0,1] R d γ 1 γ 1 γ 2 γ 2 Not continuous G 0 - C 0 -continuous γ 1 1 = γ 2 0
Continuity Continuity and smoothness between parametric curves γ 1, γ 2 : [0,1] R d γ 1 γ 2 γ 2 0 γ 1 1 γ 1 γ 1 1 γ 2 0 γ 2 G 1 -continuous G 0 + tangent vectors parallel γ 1 1 = pγ 2 0, p R + C 1 -continuous C 0 + tangent vectors parallel γ 1 1 = γ 2 0
Continuity Continuity and smoothness between parametric curves γ 1, γ 2 : [0,1] R d G 2 -continuous G 1 + γ 1 1 = pγ 2 0, p R + C 2 -continuous C 1 + γ 1 1 = γ 2 0 G 2 smooth reflections
LAGRANGE INERPOLAION
Lagrange Interpolation Given a set of points: t i, p i, t R, p i R d Find a polynomial P such that: i P t i = p i t 2, p 2 t 1, p 1 t 3, p 3
Lagrange Interpolation Given a set of n points: t i, p i, t R, p i R d Find a polynomial P such that: i P t i = p i For each point associate a Lagrange basis polynomial: t 2, p 2 L i n t = j j i t t j t i t j t 1, p 1 t 3, p 3 t 1, 0 t 3, 0 p 2 L 2 n t (i j) L n i t j = 0 L n i t i = 1
Lagrange Interpolation Given a set of n points: t i, p i, t R, p i R d Find a polynomial P such that: i P t i = p i For each point associate a Lagrange basis polynomial: t 2, p 2 L i n t = j j i t t j t i t j t 1, p 1 t 3, p 3 Add the Lagrange basis with points as weights: P t = i Lagrange basis n n n P t = L 0 L 1 L n 1 L n i t p i p 0 x p 0 y p 0 z p 1 x p 1 y p 1 z p n 1 x p n 1 y p n 1 z
Lagrange Interpolation Given a set of n points: t i, p i, t R, p i R d Find a polynomial P such that: i P t i = p i For each point associate a Lagrange basis polynomial: L i n t = j j i t t j t i t j Add the Lagrange basis with points as weights: Given 2 points L 0 2 t = t t 1 t 0 t 1 L 1 2 t = t t 0 t 1 t 0 P t = linear interpolation Given 3 points L 0 3 t = t t 1 t 0 t 1 t t 2 t 0 t 2 P t = quadratic interpolation P t = i p i L i n t
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
SPLINES
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 P t Q t R t S t
Linear Interpolation - Defined by two points: p 1, p 2 - Searching for P t such that: - P 0 = p 1 - P 1 = p 2 - Degree of P is 1 Basis: 1 t = 1 t 2 t = t 1 1 2 1 t Linear basis P t = p 1 1 t + p 2 2 (t) P t = 1 t t p 1 p 2
Linear Interpolation 0 1 1 1 monomial basis t 1 1 t t Linear basis 1 1 1 0 P t = M 1 1 1 0 p 1 p 2
Linear Interpolation P t = M 1 1 1 0 p 1 p 2 C 0 -continuous
Cubic Hermite Interpolation - Defined by - two points: p 1, p 2 - two tangents: t 1, t 2 - Searching for P t such that: - P 0 = p 1 - P 0 = t 1 - P 1 = t 2 - P 1 = p 2 - Degree of P is 3 Basis: H 0 3 t =? H 1 3 t =? H 2 3 t =? H 3 3 t =?
Cubic Hermite Interpolation - Defined by - two points: p 1, p 2 - two tangents: t 1, t 2 - Searching for P t such that: - P 0 = p 1 - P 0 = t 1 - - P 1 = t 2 P 1 = p 2 t 3 t 2 t 1 - Degree of P is 3 H 1 H 0 3 t H 1 3 t H 2 3 t H 3 3 t Basis: H H 0 3 t =? H 1 3 t =? H 2 3 t =? H 3 3 t =? P t = M H p 1 t 1 t 2 p 2 = M H G
Cubic Hermite Interpolation - Defined by - two points: p 1, p 2 - two tangents: t 1, t 2 - Searching for P t such that: - P 0 = p 1 - P 0 = t 1 - P 1 = t 2 - P 1 = p 2 - Degree of P is 3 P t = t 3 t 2 t 1 1 H G P t = 3t 2 2t 1 0 H G p 1 = P 0 = 0 0 0 1 H G t 1 = P 0 = 0 0 1 0 H G t 2 = P 1 = 3 2 1 0 H G p 2 = P 1 = 1 1 1 1 H G p 1 t 1 t 2 p 2 = 0 0 0 1 0 0 1 0 3 2 1 0 1 1 1 1 H p 1 t 1 t 2 p 2
Cubic Hermite Interpolation - Defined by - two points: p 1, p 2 - two tangents: t 1, t 2 - Searching for P t such that: - P 0 = p 1 - P 0 = t 1 - P 1 = t 2 - P 1 = p 2 - Degree of P is 3 H = 0 0 0 1 0 0 1 0 3 2 1 0 1 1 1 1 1 = 2 1 1 2 3 2 1 3 0 1 0 0 1 0 0 0
Cubic Hermite Interpolation - Defined by - two points: p 1, p 2 - two tangents: t 1, t 2 - Searching for P t such that: - P 0 = p 1 - P 0 = t 1 - P 1 = t 2 - P 1 = p 2 - Degree of P is 3 Basis: H 0 3 t = 1 t 2 (1 + 2t) H 1 3 t = t 1 t 2 H 2 3 t = t 2 t 1 H 3 3 t = 3 2t t 2 H = 2 1 1 2 3 2 1 3 0 1 0 0 1 0 0 0 H 0 3 t H 1 3 t H 2 3 t H 3 3 t H 0 3 H 3 3 H 1 3 H 2 3
Cubic Hermite Interpolation G 1 -continuous C 1 -continuous
Bézier - Defined by - b 0 - start point - b 3 - end point - b 1, b 2 - control points that are approximated - Searching for P t such that: - P 0 = b 0 - P 0 = 3 b 1 b 0 - P 1 = 3 b 3 b 2 - P 1 = b 3 - Degree of P is 3
Bézier - Defined by - b 0 - start point - b 3 - end point - b 1, b 2 - control points that are approximated - Searching for P t such that: - P 0 = b 0 - P 0 = 3 b 1 b 0 - P 1 = 3 b 3 b 2 - P 1 = b 3 - Degree of P is 3 p 1 t 1 t 2 p 2 = 1 0 0 0 3 3 0 0 0 0 3 3 0 0 0 1 b 0 b 1 b 2 b 3 P t = M H BH G
Bézier - Defined by - b 0 - start point - b 3 - end point - b 1, b 2 - control points that are approximated - Searching for P t such that: - P 0 = b 0 - P 0 = 3 b 1 b 0 - P 1 = 3 b 3 b 2 - P 1 = b 3 - Degree of P is 3 Basis: B 3 0 t = 1 t 3 B 3 1 t = 3 1 t 2 t B 3 2 t = 3 1 t t 2 B 3 3 t = t 3 Bernstein polynomial: B n i t = n t i i 1 t n i B = H BH = B 0 3 P t = i B 1 3 1 3 3 1 3 6 3 0 3 3 0 0 1 0 0 0 B 2 3 b i B i n t B 3 3
Bézier properties Advantages: End point interpolation angents explicitly specified Smooth joints are simple P 3, P 4, P 5 collinear G 1 continuous P 5 -P 4 =P 4 -P 3 C 1 continuous Geometric meaning of control points Affine invariance Convex hull property For 0<t<1: B i (t) 0 Symmetry: B i (t) = B n-i (1-t) Disadvantages Smooth joints need to be maintained explicitly Automatic in B-Splines (and NURBS)
DeCasteljau Algorithm Bernstein polynomial defined recursively: P t = b i B i n t B i n t = n i t i 1 t n i = tb n 1 i 1 t + 1 t B n 1 i t i Recursive point computation: b 0 i t = b i b k+1 k i t = tb i+1 t + 1 t b i k t i i i b i k t B i n k t = b k i t tb n k 1 i 1 t + b k i t 1 t B n k 1 i t = k b i+1 t tb i n k 1 t + b i k t 1 t B i n k 1 t = i b i k+1 t B i n k 1 t P t = = b 0 n t
DeCasteljau Algorithm t= 0.5
Catmull-Rom-Splines Goal Smooth (C 1 )-joints between (cubic) spline segments Algorithm angents given by neighboring points P i-1 P i+1 Construct (cubic) Hermite segments Advantage Arbitrary number of control points Interpolation without overshooting Local control
Catmull-Rom-Splines - Each segment defined by - c 1 - start point - c 2 - end point - c 0, c 3 - neighbor segment points - Searching for P t such that: - P 0 = c 1 - P 0 = 1 2 c 2 c 0 - P 1 = 1 2 c 3 c 1 - P 1 = c 2 - Degree of P is 3
Catmull-Rom-Splines - Each segment defined by - c 1 - start point - c 2 - end point - c 0, c 3 - neighbor segment points - Searching for P t such that: - P 0 = c 1 - P 0 = 1 2 c 2 c 0 - P 1 = 1 2 c 3 c 1 - P 1 = c 2 - Degree of P is 3 p 1 t 1 t 2 p 2 = 0 1 0 0 1 1 0 2 2 0 0 1 2 0 1 2 0 0 1 0 c 0 c 1 c 2 c 3 P t = M H CH G
Catmull-Rom-Splines - Each segment defined by - c 1 - start point - c 2 - end point - c 0, c 3 - neighbor segment points - Searching for P t such that: - P 0 = c 1 - P 0 = 1 2 c 2 c 0 - P 1 = 1 2 c 3 c 1 - P 1 = c 2 - Degree of P is 3 Basis: C 0 t = 1 t t 1 2 2 C = H BH = 1 2 1 3 3 1 2 5 4 1 1 0 1 0 0 2 0 0 C 1 t = 1 2 t 1 (3t2 2t 2) C 2 t = 1 2 t 3t2 4t 1 C 3 t = 1 2 t2 t 1
Catmull-Rom-Splines 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. Control points should be equidistant in time
Choice of Parameterization Problem Often only the control points are given How to obtain a suitable parameterization t i? Example: Chord-Length Parameterization t 0 = 0 t i = j=1 Arbitrary up to a constant factor»warning Distances are not affine invariant! Shape of curves changes under transformations!! i dist P i P i 1
Choice of Parameterization Chord-Length versus uniform Parameterization Analog: hink P(t) as a moving object with mass that may overshoot Uniform Chord-Length