CSCE 441: Keyframe Animation/Smooth Curves (Cont.) Jinxiang Chai Key-frame Interpolation • Given parameter values at key frames, how to interpolate parameter values for inbetween frames. θ t Key-frame Interpolation • Given parameter values at key frames, how to interpolate parameter values for inbetween frames. θ t Key-frame Interpolation • Given parameter values at key frames, how to interpolate parameter values for inbetween frames. θ t Nonlinear interpolation Review: Natural cubic cruves a x t 3 bxt 2 cxt d x Qx (t ) Review: Natural cubic cruves a x t 3 bxt 2 cxt d x Qx (t ) t 3 t2 ax bx t 1 Qx (t ) c x d x Review: Natural cubic cruves a x t 3 bxt 2 cxt d x Qx (t ) t t t t t 3 3 1 3 2 3 3 3 4 ax bx t 1 Qx (t ) c x d x t2 t1 2 t2 2 t3 2 t4 2 t1 1 a x Qx (t1 ) t 2 1 bx Qx (t 2 ) c Q (t ) t3 1 x x 3 t 4 1 d x Qx (t 4 ) a x t13 t12 t1 3 2 bx t 2 t 2 t 2 c t 3 t 2 t x 33 3 2 3 d t x 4 t4 t4 1 1 1 1 1 Qx (t1 ) Qx (t 2 ) Q (t ) x 3 Q (t ) x 4 Review: Natural cubic curves Q(t ) t 3 t 2 ax bx t 1 t 3 t 2 c x d x t13 3 t t 1 2 3 t3 t 3 4 2 t1 t2 2 t2 t3 2 t3 t4 2 t4 t1 1 1 1 1 1 Q(t1 ) Q ( t ) 2 Q(t ) 3 Q(t ) 4 Review: Hermite Curves P1: start position P4: end position R1: start derivative R4: end derivative R1 P1 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 R1 P1 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 Herminte basis matrix R1 P1 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 Herminte basis matrix 2t 3 3t 2 1 2t 3 3t 2 P1 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 2t 3 3t 2 1 2t 3 3t 2 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 2t 3 3t 2 1 2t 3 3t 2 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 2t 3 3t 2 1 2t 3 3t 2 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 2t 3 3t 2 1 2t 3 3t 2 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 P4 R4 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 2t 3 3t 2 1 2t 3 3t 2 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 Hermite basis functions P4 R4 Review: Hermite Curves Q (t ) t 3 t2 basis function 1 1 1 0.9 0.8 0.8 0.7 0.7 0.6 0.6 0.5 0.5 0.4 0.4 0.3 0.3 R4 P1 basis function 1 0.9 P4 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 2t 3 3t 2 1 2t 3 3t 2 basis function 1 basis function 1 0.16 0 0.14 -0.02 0.12 -0.04 0.1 -0.06 0.08 -0.08 0.06 -0.1 0.04 -0.12 0.2 0.2 0.02 0.1 0.1 0 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 0 -0.14 0 20 40 60 80 100 120 -0.16 0 20 40 60 80 100 120 Review: Hermite Curves Q (t ) t 3 t2 R1 1 p1 2 2 1 3 3 2 1 p4 t 1 0 0 1 0 R1 1 0 0 0 R4 P4 R4 P1 P1 P 3 2 3 2 4 t 2t t t t R 1 R 4 2t 3 3t 2 1 2t 3 3t 2 P1 (2t 3 3t 2 1) P4 (2t 3 3t 2 ) R1 (t 3 2t 2 t ) R4 (t 3 t 2 ) 1 1 0.9 0.9 *P1 = 0.8 0.7 + *P4 + 0.8 0.7 0.6 0.6 0.5 0.5 0.4 0.4 0.3 0.3 0 *R1 0.14 0.12 + *R4 -0.02 -0.04 0.1 -0.06 0.08 -0.08 0.06 -0.1 0.04 -0.12 0.2 0.2 0.02 0.1 0.1 0 0.16 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 0 -0.14 0 20 40 60 80 100 120 -0.16 0 20 40 60 80 100 120 Review: Bezier Curves R1 3(v1 v0 ) R2 3(v3 v2 ) P1 v0 P4 v3 Review: Bezier Curves Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Review: Bezier Curves Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 t 3 3t 2 3t 1 3t 3 6t 2 3t 1 v0 0 v1 0 v2 0 v3 3t 3 3t 2 v0 v 3 1 t v 2 v 3 Review: Bezier Curves Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 t 3 3t 2 3t 1 3t 3 6t 2 3t 1 v0 0 v1 0 v2 0 v3 3t 3 3t 2 v0 v 3 1 t v 2 v 3 1 0.45 0.45 1 0.9 0.4 0.4 0.9 0.35 0.35 0.8 0.8 0.7 0.7 0.3 0.3 0.25 0.25 0.2 0.2 0.15 0.15 0.1 0.1 0.05 0.05 0.6 0.6 0.5 0.5 0.4 0.4 0.3 0.3 0.2 0.1 0 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 0 0.2 0.1 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 Review: Bezier Curves Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 t 3 3t 2 3t 1 3t 3 6t 2 3t 3t 3 3t 2 v0 v 3 1 t v 2 v 3 v0 (t 3 3t 2 3t 1) v1 (3t 3 6t 2 3t ) v2 (3t 3 3t 2 ) v3 t 3 1 0.45 0.45 1 0.9 0.4 0.4 0.9 0.35 0.35 0.8 0.7 = *v0 0.6 0.5 + *v1 0.3 0.25 + 0.8 *v2 0.3 0.25 0.2 0.2 0.15 0.15 0.1 0.1 0.05 0.05 + 0.4 0.6 0.5 0.4 0.3 0.3 0.2 0.1 0 *v3 0.7 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 0 0.2 0.1 0 20 40 60 80 100 120 0 0 20 40 60 80 100 120 Review: Different basis functions • Cubic curves: Q(t ) t 3 t 2 ax b t 1 x t 3 t 2 c x d x • Hermite curves: Q (t ) t 3 t1 2 t2 2 t3 2 t4 2 t1 1 t 2 1 t3 1 t 4 1 1 Q(t1 ) Q(t 2 ) Q(t ) 3 Q(t ) 4 t2 1 P1 2 2 1 3 3 2 1 P4 t 1 0 0 1 0 R1 1 R 0 0 0 4 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 • Bezier curves: Q (t ) t 3 t13 3 t t 1 2 3 t3 t 3 4 1 P1 0 P2 0 P3 0 P4 Complex curves Suppose we want to draw or interpolate a more complex curve Complex curves • Suppose we want to draw or interpolate a more complex curve How can we represent this curve? Complex curves • Suppose we want to draw a more complex curve • Idea: we’ll splice together a curve from individual segments that are cubic Béziers Complex curves • Suppose we want to draw or interpolate a more complex curve • Idea: we’ll splice together a curve from individual segments that are cubic Béziers Splines • A piecewise polynomial that has a locally very simple form, yet be globally flexible and smooth Splines • There are three nice properties of splines we’d like to have - Continuity - Local control - Interpolation Continuity • C0: points coincide, velocities don’t • C1: points and velocities coincide • What’s C2? - points, velocities and accelerations coincide Continuity • Cubic curves are continuous and differentiable • We only need to worry about the derivatives at the endpoints when two curves meet Local control • We’d like our spline to have local control - that is, have each control point affect some well-defined neighborhood around that point Local control • We’d like our spline to have local control - that is, have each control point affect some well-defined neighborhood around that point Local control • We’d like our spline to have local control - that is, have each control point affect some well-defined neighborhood around that point Interpolation • Bézier curves are approximating - The curve does not (necessarily) pass through all the control points - Each point pulls the curve toward it, but other points are pulling as well • Instead, we may prefer a spline that is interpolating - That is, that always passes through every control point B-splines • We can join multiple Bezier curves to create B-splines • Ensure C2 continuity when two curves meet Derivatives at end points Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Derivatives at end points Q (t ) t 3 Q (t ) 3 t 2 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 v0 0 v1 0 v2 0 v3 Derivatives at end points Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Q (t ) 3 t 2 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 (t ) 6 t Q 1 3 3 3 6 3 2 0 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Derivatives at end points Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Q (t ) 3 t 2 (t ) 3 t 2 Q Derivatives at end points Q (t ) t 3 t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Q (t ) 3 t 2 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 (t ) 6t Q 1 3 3 3 6 3 2 0 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 3 3 3 6 3 Q (0) 3 t * 0 2 2 * 0 1 0 3 3 0 1 0 0 3(v1 v0 ) 1 v0 0 v1 0 v2 0 v3 Derivatives at end points Q (t ) t 3 Q (t ) 3 t 2 (t ) 6 t Q t2 1 3 3 3 6 3 t 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 3 3 3 6 3 2t 1 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 1 3 3 3 6 3 2 0 0 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Q (0) 3(v1 v0 ) Q (1) 3(v v ) 3 2 (0) 6(v 2v v ) Q 0 1 2 (1) 6(v 2v v ) Q 3 2 1 Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint Qv (1) Qw (0) Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint Qv (1) Qw (0) Q (1) Q (0) v w (1) Q (0) Q v w Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint v3 w0 Qv (1) Qw (0) Q (1) Q (0) 3(v3 v2 ) 3( w2 w1 ) (1) Q (0) Q v w 6(v3 2v2 v1 ) 6( w0 2w1 w2 ) v w Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint v3 w0 3(v3 v2 ) 3( w2 w1 ) 6(v3 2v2 v1 ) 6( w0 2w1 w2 ) Continuity in B splines • Suppose we want to join two Bezier curves (V0, V1, V2,V3) and (W0, W1, W2, W3) so that C2 continuity is met at the joint v3 w0 3(v3 v2 ) 3( w2 w1 ) 6(v3 2v2 v1 ) 6( w0 2w1 w2 ) w0 v3 w1 2v3 v2 w2 v1 4v3 4v2 Continuity in B splines What does this derived equation mean geometrically? w2=v1+4v3-4v2 - What is the relationship between a, b and c, if a = 2b - c? de Boor points • Instead of specifying the Bezier control points, let’s specify the corners of the frames that forms a B-spline • These points are called de Boor points and the frames are called A-frames de Boor points • What is the relationship between Bezier control points and de Boor points? Verify this by yourself! B spline basis matrix Building complex splines • Constraining a Bezier curve made of many segments to be C2 continuous is a lot of work - for each new segment we have to add 3 new control point - only one of the control points is really free • B-splines are easier (and C2) - First specify 4 vertices (de Boor points), then one per segment B splines properties √ Continuity √ Local control x Interpolation Catmull-Rom splines • If we are willing to sacrifice C2 continuity, we can get interpolation and local control. • If we set each derivative to be a constant multiple of the vector between the previous and the next controls, we get a Catmull-Rom spline Catmull-Rom splines Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) The segment is controlled by p1,p2,p3,p4 Q ( 0) p 2 Q (1) p3 Q (0) ( p3 p1 ) Q (1) ( p p ) 4 0.5 2 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) The segment is controlled by p1,p2,p3,p4 Q ( 0) p 2 Q (1) p3 Q (0) ( p3 p1 ) Q (1) ( p p ) 4 2 Catmull-Rom splines The effect of t: how sharply the curve bends at the control points Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) The segment is controlled by p1,p2,p3,p4 Q ( 0) p 2 Q (1) p3 Q (0) ( p3 p1 ) Q (1) ( p p ) 4 2 Q ( 0) 0 Q ( 1 ) 0 Q (0) Q (1) 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) From Hermite curves Q(t ) t 3 t 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) t 1 0 0 1 0 Q (0) 1 0 0 0 Q (1) Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) From Hermite curves Q(t ) t 3 t 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) t 1 0 0 1 0 Q (0) 1 0 0 0 Q (1) Q ( 0) 0 Q (1) 0 Q (0) Q (1) 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) From Hermite curves Q(t ) t 3 t 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) t 1 0 0 1 0 Q (0) 1 0 0 0 Q (1) Q(t ) t 3 t2 Q ( 0) 0 Q (1) 0 Q (0) Q (1) 0 1 0 2 2 1 3 3 2 1 0 t 1 0 0 1 0 1 0 0 0 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) Q(t ) t 3 t3 t2 1 0 2 2 1 3 3 2 1 0 t 1 0 0 1 0 1 0 0 0 0 t2 2 t 1 0 2 2 3 3 2 0 1 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 p1 p2 0 p3 0 p4 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) Q(t ) t 3 t3 t2 1 0 2 2 1 3 3 2 1 0 t 1 0 0 1 0 1 0 0 0 0 t2 2 t 1 0 2 2 3 3 2 0 1 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 p1 p2 0 p3 0 p4 Catmull-Rom splines ( p3 p1 ) ( p4 p2 ) Q(t ) t 3 t3 t2 1 0 2 2 1 3 3 2 1 0 t 1 0 0 1 0 1 0 0 0 0 t2 2 t 1 0 2 2 3 3 2 0 1 0 0 0 p1 0 1 0 p2 0 0 p3 0 p4 1 p1 p2 0 p3 0 p4 What do we miss? Catmull-Rom splines ? ? Catmull-Rom splines ( p4 p3 ) ( p1 p0 ) Catmull-Rom splines • Catmull-Rom splines have C1 continuity (not C2 continuity) • Do not lie within the convex hull of their control points. Catmull-Rom splines • Catmull-Rom splines have C1 continuity (not C2 continuity) • Do not lie within the convex hull of their control points. Catmull-Rom splines properties X Continuity (C2) √ Local control √ Interpolation Keyframe Interpolation 3 c3 2 A c2 c1 t=0 1 t=50ms Curves in the animation Interpolate each parameter separately Each animation parameter is described by a 2D curve Q(u) = (x(u), y(u)) Treat this curve as θ = y(u) t = x(u) θ t u u where θ is a variable you want to animate and t is a time index. We can think of the results as a function: θ(t) Keyframing interpolation is a two-step algorithm: - Compute the spline parameter u corresponding to the time t: u x 1 (t ) t=x(u) u Keyframing interpolation is a two-step algorithm: - Compute the spline parameter u corresponding to the time t: u x 1 (t ) how to evaluate the inverse function? Keyframing interpolation is a two-step algorithm: Compute the spline parameter u corresponding to the time t: u x 1 (t ) how to evaluate the inverse function? - linear function: easy (t=u) - complex function: finite difference or numerically root finding Keyframing interpolation is a two-step algorithm: Compute the spline parameter u corresponding to the time t: u x 1 (t ) how to evaluate the inverse function? - linear function: easy - complex function: finite difference or numerically root finding Compute the θ corresponding to the spline parameter u: θ = y(u) u Outline • • • • • Process of keyframing Key frame interpolation Hermite and bezier curve Splines Speed control Spline parameterization The spline is parameterized by u (0<=u<=1) and not by time t. Q (t ) u 3 u2 1 3 3 3 6 3 u 1 3 3 0 1 0 0 1 v0 0 v1 0 v2 0 v3 Spline parameterization The spline is parameterized by u (0<=u<=1) and not by time t. Q (t ) u 3 u2 1 3 3 3 6 3 u 1 3 3 0 1 0 0 Hard to deal with the questions like - What is the location of point p at time t - What is the velocity of point p at time t - What is the acceleration a of a point p at time t 1 v0 0 v1 0 v2 0 v3 Spline parameterization Solution: reparameterize the curve in terms of t - express spline as a function of the arc length s: u=g(s) - express the arc length s as a function of t: s=f(t) Speed control • Simplest form is to have constant velocity along the path s=f(t) Arc-length reparameterization • Now we want a way to find u given a particular arclength s: u=g(f(t)) • Not possible analytically for most curves (e.g. Bsplines) Finite difference • Sample the curve at small intervals of the parameter and determine the distance between samples • Use theses distances to build a table of arclength for this particular curve: (ui,si) What’s parametric value for the arc length .08? Finite difference • Sample the curve at small intervals of the parameter and determine the distance between samples • Use theses distances to build a table of arclength for this particular curve: (ui,si) Finite difference • Sample the curve at small intervals of the parameter and determine the distance between samples • Use theses distances to build a table of arclength for this particular curve: (ui,si) What’s parametric value for the arc length .08? Finite difference • Sample the curve at small intervals of the parameter and determine the distance between samples • Use theses distances to build a table of arclength for this particular curve: (ui,si) What’s parametric value for the arc length .08? Finite difference • Sample the curve at small intervals of the parameter and determine the distance between samples • Use theses distances to build a table of arclength for this particular curve: (ui,si) What’s parametric value for the arc length .05? A linear interpolation of 0.00 and 0.05 Speed control recipe • Given a time t, lookup the corresponding arclength S in the speed curve • For S, look up the corresponding value of u in the reparameterization table • Evaluate the curve at u to obtain the correct interpolated position for the animated object for the given time t