Interpolating Key Vales EECS 487: Interactive Compter Graphics f Keys Lectre 33: Keyframe interpolation and splines Cbic splines The key vales of each variable may occr at different frames The interpolation of key vales of a variable defines a crve df/dt t Frame positions t Hodgins Potential Problem with Interpolation The crve may ndershoot and case inter-penetration Soltion: add key frames (= control points)! Motion Control Crve Given the key frames, how wold yo mathematically represent a control crve that interpolates (passes throgh) the control points?
Motion Control Crve We don t want motion with nnatral (painfl) twists and bends jerkiness Desired characteristics of the motion control crve: ser controlled with control points defines a smooth and continos crve ability to evalate derivatives stable: doesn t cross over itself local control of crve shape change to one part of the crve doesn t effect the entire crve Which representation of crves has these characteristics? Representation of Crves Polyline: piecewise linear crves given a seqence of vertices (control points) connect each pair of consective vertices with a line segment a smooth crve will need a continos set of points on the plane (or in space) hard to get precise, smooth reslts too mch data, too hard to work with Explicit: y = f(x) y + easy to generate points single-valed for each x mst be a fnction: big limitation, e.g., vertical lines? rotations completely change representation p k x Hodgins Y Representation of Crves Implicit: f(x, y) = 0 + spports mltiple vales for each x + easy to test if on, or to either side, of crve hard to generate points Parametric: (x, y) = (f(), g()) parameterization of a crve how a change in moves yo along a given crve in xyz space + spports mltiple vales for each x + fairly easy to generate points + can describe trajectories, the speed at which we move on the crve We want some kind of parametric crve to control motion! f (x, y) = x 2 + y 2 r 2 = 0 (x, y) = (r cos θ, r sin θ) r θ r Schlze,Y Parametric Crves Define a mapping from parameter space (e.g.,, sally [0,]), to points in 2D, 3D, etc. Parameter space mapping: D: f() maps to points on crve 0 mapping: f: (x, y, z) 2D: [f(), g()] maps to points on srface Chenney
Parametric Crves In general, described by a vector-valed fnction, i.e., n scalar fnctions, of D parameter space x() p() = y() z() Tangent of the crve, t() = p () = [x () y () z ()] T, is the velocity of movement and t() is the speed of movement T() = t()/ t() is the nit tangent of the crve y() y(t) y(t) y() 2 0 2 nd crve st crve 2 t p() x() x(t) x() x(t) Foley, Van Dam, Schlze Parameter Mapping x() p() = y() z() The coordinate fnctions can be any fnction: polynomials of arbitrary degree trigonometric fnctions exponentiations logarithms Forier series, etc. 2 0 2 nd crve st crve We ll only consider polynomials; more complex fnctions are harder to deal with y() y(t) y(t) y() 2 t p() x() x(t) x() x(t) FvD,Schlze,Merrell Polynomial Fnctions Linear ( st order): f () = a 0 + a Qadratic (2 nd order): f () = a 0 + a + a 2 2 Cbic (3 rd order): f () = a 0 + a + a 2 2 + a 3 3 f () f () f () Parametric Polynomial Crves Linear: f() = a 0 + a, 0 Evalated as: x() a 0x + a x f() = y() = a 0y + a y z() a 0z + a z y z a 0 x Qadratic: f() = a 0 + a + a 2 2 y Cbic: z x f() = a 0 + a + a 2 2 + a 3 3 a y z Schlze x Schlze
Canonical Form Splines have the canonical form: f() = a 0 + a + 2 a 2 +...+ n a n, n = i a i, i=0 = a, = 2... k 0, [ ], Non-niqe Even restricted to polynomial fnctions, the same parametric crve may have mltiple descriptions p() = [ ] T p() = [ 3 3 ] T Schlze O Brien x() Lagrange Interpolation Problem: given n+ control points, how do we define a parametric crve that interpolates all points? An n-degree polynomial (Lagrange polynomial) can interpolate any n+ points Problem: small-degree Lagrange polynomials are fine bt high degree ones are too wiggly x() x() Introdcing... Splines A spline is a piecewise parametric polynomial fnction Many low degree (mostly cbic) splines can be pieced together to interpolate a given set of control points, with garanteed continity Piecewise definition gives local control of crve 8-degree polynomial joined splines splines vs. polynomial Drand,Hodgins 8-degree polynomial 0-degree polynomial Demo: http://www.math.cla.ed/~baker/java/hoefer/twodemos.htm Drand
Splines Originally sed by draftsmen (draghtsmen in English, loftsmen in shipbilding) to draw life-size crves Physically, a stiff piece of metal that can be bent into desired shape for tracing, and held in place with dcks (the mathematical eqivalent of these metal strips is the natral-cbic spline) Splines Many ses in CG: 2D illstration (e.g., Adobe Illstrators) font definition 3D modeling color ramps animation: trajectories in general, interpolate keyframes control points Drand,Marschner,Hanrahan Advantages of Splines Specified by a few control points efficient for UI efficient for storage Gives a smooth parametric polynomial crve p() defined in Cartesian coordinates by x() and y() convenient for animation where is time convenient for tessellation in modeling as can be discretized and the crve approximated with small linear segments Drand Linear Splines The two coefficients of a first-order, linear polynomial can be determined from its two end-points: f() = a 0 + a = f(0) = f(0) = a 0 + 0a = a 0 = f() = a 0 + a = a 0 + a in matrix form: = 0 a 0 where C is called the constraint matrix a, p = Ca, = f() Remember that the p i s and a i s are themselves vectors [Schlze, wikipedia]
Basis Matrix Two Views of Splines Schlze Then a = C p, a 0 a = 0 a 0 = a = Let s call B = C the blending/basis matrix (for reasons to be explained later), then: f() = a = Bp, f() = f() = f() =! f() = a 0 + a B p a 0 a B p Coefficients (a i s) can be compted from control points p i s,!where!b = 0 f() = B ( ) f() = ( ) f() = ( ) + Each point on the crve is a linear blending of the control points p i s Zhang Blending Fnctions b 0 () b () Non-linear Interpolations f() = ( ) + b 0 () b () The weights b 0 () = ( ) and b () = are called the blending fnctions Linear interpolation: object moves at constant speed in-between vales at eqal intervals along straight lines f() = a = Bp = ( ) + = b i ()p i expresses the polynomial as a weighted sm (combination) of the control points: contribtion of each point as changes (and we don t have to solve for the a s (coefficient vectors)!) i=0 Schlze Qadratic interpolation with constant speed and eqal spacing of in-between vales Cbic interpolation with acceleration Hodgins
Qadratic Splines Qadratic (2 nd degree) spline f() = a 0 + a + a 2 2 are specified by three coefficients and can be solved by, for example, three points: = f(0) = a 0 + 0 a + 0 2 a 2 = f(0.5) = a 0 + 0.5 a + 0.5 2 a 2 = f() = a 0 + a + 2 a 2 or by a point and its first and second derivatives: = f(0.5) = a 0 + a + 2 a 2 = a 0 + 0.5 a + 0.5 2 a 2 = f '(0.5) = a + 2a 2 = a + 2 * 0.5a 2 qadratic linear The control points are the geometric constraints or bondary conditions and are completely ser specified User-Specified Control Points Given control points,,, the qadratic spline: f() = a 0 + a + a 2 2, [0,] can describe any of the following motion: 0 ½ 0 ½ 0 ½ 0 ¼ = f ''(0.5) = 2a 2 = 2a 2 Zhang Gilles Blending Fnctions Blending Fnctions For the qadratic spline specified as: The qadratic spline specified as: = f(0.5) = a 0 + a + 2 a 2 = a 0 + 0.5 a + 0.5 2 a 2 = f '(0.5) = a + 2a 2 = a + 2 *0.5a 2 = f(0.5) = a 0 + a + 2 a 2 = a 0 + 0.5 a + 0.5 2 a 2 = f '(0.5) = a + 2a 2 = a + 2 * 0.5a 2 = f ''(0.5) = 2a 2 = 2a 2 has C =.5.25 0 0 0 2 and B = C =.5.25 0.5 0 0.5 = f ''(0.5) = 2a 2 = 2a 2 its.5.25.5.25 C = 0 and B = C = 0.5 0 0 2 0 0.5 2 f() = b i ()p i = 2 i=0.5.25 0.5 0 0.5
Desired Properties of Blending Fnctions Affine invariance: k affine combination: b i () =, 0 i=0 to transform a crve, we can transform the control points and then regenerate the crve perspective transformations are non-affine only rational basis can be perspective transformed (see NURBS) Desired Properties of Blending Fnctions Convex hll property: convex combination of control points:: any point on the crve is a convex combination of its control points the crve is a weighted average of the control points no point on the crve lies otside the convex hll makes clipping, clling, picking, etc. simpler k b i () =, b i () 0, 0 i=0 Marschner Interpolate or Approximate? A spline can: interpolate some or all control points sonds more sefl, bt can be ndesirable becase: less continity more nstable, ringing lack of control between points approximate the control points: control points not on the spline control points inflence the shape of spline, bt does not specify it exactly gain local control and better behavior of spline when needed, control points can be compted sch that the spline interpolates some of them Splines To interpolate/approximate n+ control points reqires a spline of order n: 3 control points: qadratic spline 4 control points: cbic spline For cbic with for coefficients, we d need for knowns to solve the polynomials for example, the two endpoints and their first derivatives Recall: control points are the geometric constraints or bondary conditions and are completely ser specified Drand Gilles,Merrell
Cbic Splines Examples of (Hermite) cbic splines: y() : st end point : first derivative of st end point : 2nd end point : first derivative of 2nd end point Joining Splines To interpolate a large nmber of control points, we can join together a nmber of splines Where the splines meet are called knots/joints Each line segment is parameterized by its endpoints. The end of one segment is shared with the beginning endpoint of the next segment. Foley, van Dam 92 x() Two isses:. whether the combined crve has local control 2. smoothness of overall combined crve Gilles,Merrell,Shirley Local Control Each line segment is parameterized by its endpoints. Joint Smoothness no local control has local control The end of one segment is shared with the beginning endpoint of the next segment. Moving a control point cases a change only in a localized region. Each line segment is parameterized by its endpoint and its centerpoint. The endpoint of segment two is eqated to the "free" end of segment one. The endpoint of segment three is eqated to the "free" end of segment two, etc. Smoothness of overall combined crve, sefl for: compting normals across joints in shading parameter interpolation between keyframes in animation Two types of smoothness measres:. Parametric continity: continity of coordinate fnctions (x(), y()) sefl for trajectories 2. Geometric continity: continity of the crve/srface itself sefl in defining shapes (see modeling lectres) A change in any control point cases ALL later line segments to be affected. [Shirley]
Measres of Joint Smoothness Parametric continity: y() y (t ) 0 th order, C 0 crve segments meet at joint: f 2 (0) = f () st order, C st derivatives, velocities, eqal at joint: f 2 (0) = f () 2 nd order, C 2 2 nd derivatives, accelerations, eqal at joint S Foley, van Dam 92 C 0 C C 2 Join point C 2 C C C 0 0 2 x(t x() ) Cbic Splines Reasons we prefer to work with cbic splines in CG: cbics allow for C 2 continity, qadratics offer only C lower degree polynomials are not flexible enogh the three points specifying a second-order polynomial define a plane in which the polynomial lies cbics are the lowest order polynomials that can be non-planar in 3D the greater smoothness offered by qartic* and other higher-order polynomials are rarely important higher degree polynomials can introdce wiggles (oscillations) and are more expensive to compte sed mainly in designing aerodynamic crves/srfaces *don t confse qartic (4 th order) polynomial with qadric (implicit qadratic srfaces formed from conic sections) Marschner Cbic Splines A representation of cbic spline consists of: for control points (why for?) these are completely ser specified determine a set of blending fnctions Hermite Cbic Control points : position and st derivative of endpoints: f() = a 0 + a + 2 a 2 + 3 a 3 = f(0) = a 0 + 0 a + 0 2 a 2 + 0 3 a 3 There is no single best representation of cbic spline: Cbic Interpolate? Local? Continity Affine? Convex*? VD*? Hermite C n/a n/a Cardinal (Catmll-Rom) except endpoints * n/a when some of the control points are tangents, not points C no no Bézier endpoints C natral C 2 n/a n/a B-Splines C 2 = f '(0) = a + 2 * 0 a 2 + 3* 0 2 a 3 = f() = a 0 + a + 2 a 2 + 3 a 3 = f '() = a + 2 * a 2 + 3* 2 a 3 Basis matrix: Constraint matrix
Hermite Cbic Blending Fnctions 3 f() = b i ()p i = 2 3 i=0 0 0 0 0 0 0 3 2 3 2 2 f() = (2 3 3 2 + ) + ( 3 2 2 + ) + ( 2 3 + 3 2 ) + ( 3 2 ) Which graph is b 0 (), b (), b 2 (), and b 3 ()? How can yo tell? b() Hint: = f (0) = f '(0) = f () = f '() Hodgins Hermite Cbic Blending Fnctions For the Hermite crve: y() 0 P pr 3 4 R f() P 4 x() is most inflential at = 0 Near = 0, mainly b 0 and b determine the crve, with b 2 and b 3 contribting Control points weighted by the blending fnctions (only y-component shown): y() y() 0 Pb 0 ()p P (t) 0,y b ()p R,y R (t) 0 sm of weighted control points y() b 2 (),y P 4 P b 3 (),y Foley, van Dam 90 Hermite Cbic Examples Recall: the control points are the geometric constraints or bondary conditions and are completely ser specified y() Tangent vector direction R at point P ; magnitde varies for each crve y() Hermite Cbic Chain Can achieve C continity with: q 0 = f 2 (0) = f () = q = f 2 '(0) = f '() = f 2 '(0) = f '() f () = q 0 q 2 f 2 () Tangent vector direction R 4 at point P P 4 P 4 ; magnitde fixed for each crve x() only s magnitde only s direction varies for each crve varies for each crve x() FvD 90 Given n control points, the chain contains (n 2)/2 cbic segments The chain interpolates the control points, provides local control and is affine invariant Shirley
Problem with Hermite Spline Mixing points and tangents as control points is awkward To get C, designer mst explicitly specify derivative at each endpoint sch that consective tangents are collinear This gets tedios... f 2 '(0) = f '() f () = q 0 q 2 f 2 () Cbic Splines A representation of cbic spline consists of: for control points (why for?) these are completely ser specified determine a set of blending fnctions There is no single best representation of cbic spline: Cbic Interpolate? Local? Continity Affine? Convex*? VD*? Hermite C n/a n/a Cardinal (Catmll-Rom) except endpoints * n/a when some of the control points are tangents, not points C no no Bézier endpoints C natral C 2 n/a n/a B-Splines C 2 Hodgins,Shirley Cardinal Cbic Spline Given n control points, a cardinal cbic spline chain has n-3 segments, it interpolates all points except the endpoints each segment i ses as control points p i-, p i, p i+, p i+2, so each segment shares control points with its 3 sbseqent neighbors local control each segment i spans only p i, p i+ the derivative at p i is determined by the vector (p i+ p i- ) the derivative at p i+ is determined by the vector (p i+2 p i ) since the third point of segment i is the second point of segment i+, the crve is C 0 - frther, the same vector determines the first derivative at the end of segment i and that at the start of segment i+, hence Cardinal cbic spline (and therefore Catmll-Rom spline) has bilt-in C continity p 4 - Cardinal Cbic Spline Canonical form: f() = a 0 + a + 2 a 2 + 3 a 3 f '() = a + 2a 2 + 3 2 a 3 Control points: = f(0) = a 0 = f() = a 0 + a + 2 a 2 + 3 a 3 f '(0) = a + 2 *0 *a 2 + 3*0 2 *a 3 f '() = a + 2 **a 2 + 3* 2 *a 3 - ( ) = f '(0) = f '(0) = a 0 + 0a + 2 a 2 + 3 a 3 ( ) = f '() = + f '() = a 0 +a + 2a 2 + 3a 3 p 4 - Constraint matrix: C = 0 0 0 0 2 3 Shirley
Cardinal Cbic Spline Cardinal splines have additional control parameters (beyond continity): tension (t) and bias (b), allowing better control of the crve between control points Cardinal Cbic Spline The tension parameter (t) controls how sharply the crve bends at the control point p i by controlling the magnitde of the tangent (f i ()): f i ' () 3 4 5 high tension sharp bend t = defalt t = 0 low tension t = low bias, ndershoot b = - overshoot b = 2 6 7 The bias parameter (b) pts weight on the left or right neighboring control point Shirley Akenine-Möller & Haines 02 Cardinal Cbic Spline with Tension ( t)( b) ( t)(+ b) f ' i () = (p i+ p i ) + (p i p i ) 2 2 For!b = 0,!f ' i () = t 2 (p i+ p i ) Let!s = t 2,!then!the!control!points!are: = f(0)! = a 0 = f()! = a 0 + a + a 2 + a 3 f '(0) =!!!!!!!!!!!!!!!!a + 2 *0 *a 2 + 3*0 2 *a 3 f '() =!!!!!!!!!!!!!!!!a + 2 **a 2 + 3* 2 *a 3 f i ' () f '(0) = s( ) = s f '(0) = a 0 + ( s )a + a 2 + a 3! f '() = s( ) = + s f '() = a 0 + s a + 2s a 2 + 3s a 3 Akenine-Möller & Haines 02 Cardinal Cbic Spline Cardinal cbic spline with bias (b) and tension (t) = 0 is also known as the Catmll-Rom spline Control points (s = ½): = f(0) = a 0 = f() = a 0 + a + a 2 + a 3 = 2f '(0) = a 0 a + a 2 + a 3 = + 2f '() = a 0 + 2a + 4a 2 + 6a 3 Constraint and Basis matrices: C = 0 0 0 2 4 6, B = C = 2-0 2 0 0 0 0 2 5 4 3 3 p 4 - Shirley
Catmll-Rom Blending Fnctions - p 4 - b () b 0 () b 2 () b 3 () Does the Catmll-Rom spline have the convex hll property? Problem with Catmll-Rom: does not interpolate endpoints and no control of derivatives at endpoints Shirley,Marschner