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 Properties: - Go through four control points - not good for local control 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 2 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 3 basis function 4 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 v0 0 v1 0 v2 0 v3 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 - the curve is always located within the convex hull based on control points. • 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 t=1 t=0 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 t=1 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=0 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 t=1 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 t=0 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 t=1 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 t=0 1 3 3 3 6 3 Q (0) 3* 0 2 2 * 0 1 0 3 3 0 0 0 1 3(v1 v0 ) 1 3 3 (0) 6 * 0 2 0 0 3 6 3 Q 3 3 0 0 0 1 6(v0 2v1 v2 ) 1 v 0 0 v1 0 v 2 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 t=1 Q (t ) 3 t 2 (t ) 6 t Q 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 t=0 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? b is the middle point of a and 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! 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 control points, 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 ) u 3 u 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) u 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 ) u 3 u 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) u 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 ) u 3 u 2 1 Q(0) 2 2 1 3 3 2 1 Q(1) u 1 0 0 1 0 Q (0) 1 0 0 0 Q (1) Q (t ) u 3 u2 Q ( 0) 0 Q (1) 0 Q (0) Q (1) 0 1 0 2 2 1 3 3 2 1 0 u 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 ) u 3 u3 u2 u2 1 0 2 2 1 3 3 2 1 0 u 1 0 0 1 0 1 0 0 0 0 2 u 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 ) u 3 u3 u2 u2 1 0 2 2 1 3 3 2 1 0 u 1 0 0 1 0 1 0 0 0 0 2 u 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 ) u 3 u3 u2 u2 1 0 2 2 1 3 3 2 1 0 u 1 0 0 1 0 1 0 0 0 0 2 u 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 ( p 4 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 Catmull-Rome Splines for Kyeframe Interpolation • Given a set of control points, interpolation splines are obtained by fitting the input points with a piecewise cubic polynomial curve that passes through every control point Catmull-Rome Splines for Kyeframe Interpolation • Fit the interpolation function between each pair of control points with a cubic function pk Pk+1 Pk+2 pk-1 Catmull-Rome Splines for Kyeframe Interpolation • Fit the interpolation function between each pair of control points with the following cubic function: p (u ) u 3 u2 2 u 1 0 2 2 3 3 2 0 1 0 pk 1 pk 0 pk 1 0 pk 2 pk Pk+1 Pk+2 pk-1 0<=u<=1 Outline • • • • • Process of keyframing Key frame interpolation Hermite and bezier curve Splines Speed control Speed Control • Click here Speed control • Time warping function to control speed (mapping from the original time line to the output time line) - positive - monotonic; you cannot reverse the time s=f(t) new timeline Original timeline Speed control • Simplest form is to have constant velocity along the path s=f(t) Speed control • Simplest form is to have constant velocity along the path s=f(t) Which one is “speed up” or which one is “slow down” Speed control • Simplest form is to have constant velocity along the path Speed up s=f(t) Slow down Speed control • Assume that the motion slows down at the beginning and end of the motion curve s=f(t) Speed control • Assume that the motion slows down at the beginning and end of the motion curve s=f(t) Adjust timing for each key frame