Animation and Quaternions Partially based on slides by Justin Solomon: http://graphics.stanford.edu/courses/cs148-1-summer/assets/lecture_slides/lecture14_animation_techniques.pdf 1
Luxo Jr. Pixar 1986 movie
A New Dimension - Time 3
4
Traditional Animation Anticipation Secondary Action Squash/Stretch 5
Specifying Animation http://sphmajor.files.wordpress.com/1/5/leaping_cat_by_animation_stock.jpg Specifying every frame is hard 6
Keyframes Automatically fill in motion between these points in time. http://graphics.stanford.edu/courses/cs148-1-summer/docs/1_anim_interact.pdf Specify significant poses 7
Not a New Idea http://www.superrune.com/technical/tutorial_breakdown.php Tweening: Not a fun job! 8
CAPS, Late 198s Digital ink and paint system. Rescuers Down Under, 199 http://img-3.timeinc.net/ew/i/11/1/6/rescuers-down-under_61.jpg Computer-Aided Production System9
CAPS, Late 198s http://www.youtube.com/watch?v=cke5u9fsgse Computer-Aided Production System1
Software for Keyframed Animation Artist specifies keyframes, computer does tweening. 11
Software for Keyframed Animation Artist specifies keyframes, computer does tweening. 1
Representing Motion http://3.bp.blogspot.com/-gig9r_-wbk8/t5pcek9leui/aaaaaaaaahc/o5is6dg_6f4/s16/ball_bounce_sketch.jpg http://www.blendernation.com/wp-content/uploads/7/9/blendermodo.png http://ncca.bournemouth.ac.uk/gallery/files/innovations/4/gonzalez_lisa_11/images/medium/thumbnail.jpg http://web.cecs.pdx.edu/~fliu/project/vbha/video%based%animation.jpg Choose structure for desired motion 13
Rigid Motion Location Representation: Position in space Interpolation: a spline Orientation Representation? Interpolation? 14
Rotation Matrices? 15
D Rotation Representation Rotation matrix Rotation angle θ Complex number e 16
Orientation and Euler Angles The orientation of any 3D object may be described by three Euler angles: successive rotations (relative to an initial orientation) around three axes: x-roll: rotation around x axis. y-roll: rotation around y axis. z-roll: rotation around z axis. The order of rotation application is important, as rotations do not commute. An obvious way to interpolate two orientations is to interpolate their Euler angles. 17
18 1 1 ) ( R x 1 1 ) ( R y 1 1 ) ( R z Rotation by Euler Angles
19 When this is: where = +, so one degree of freedom is lost. 1 ),, ( x y z R R R R 1 1 1 1 Gimbal Lock
Gimbal Lock
General Rotations Euler, 1756 v 1 n Theorem: (Euler): Any orientation can be obtained from a fixed reference orientation by a gle unique rotation around an appropriate axis in space. v Therefore, any orientation may be described by four parameters: angle and unit axis n=(n x,n y,n z ). 1
General Rotations (cont d) n Rv () Rv ( v) v v Rv ( ) Rv ( ) ( nv) ( nvn ) ( v( nvn ) ) ( nv) v n( nv)(1 ) ( nv) v nv v v R( v ) v ( nv) n v vv Rv ( ) v ( nv) Rv ( ) v ( nv) v
Quaternions Definition: A quaternion is a quadruple q=[s,v], where s is a scalar, and v a three-dimensional vector. Rotation by around unit direction n may be represented by the unit quaternion q[, n ] The 3D vector [,v] is rotated by q to: 1 R v q vq q () 3
Quaternions Hamilton 1843 Definition: A quaternion is a quadruple q=[s,v], where s is a scalar, and v a three-dimensional vector. The quaternions form a non-commutative group under the multiplication rule: q q [ s, v ] [ s, v ] 1 1 1 [ s s v v, sv s v v v ] 1 1 1 1 1 Equivalent to: q s iv x jv y kv z where i j k 1, ij k, ji k 4
Quaternions (cont d) The conjugate of q [ s,v] is q [ s,-v] q q q q 1 1 The inverse of q [ s,v] is: q -1 q q Corollary: The norm of q [ s,v] is x y z q q q s v v v q q q q 1 1 5
Special Cases Scalars: [c,(,,)] Complex numbers: [x,(y,,)] 3D Vectors: [,(x,y,z)] q q [ s, v ] [ s, v ] 1 1 1 [ ss v v, sv sv v v ] 1 1 1 1 1 6
Rotating with Quaternions Rotation by around unit direction n may be represented by the unit quaternion The 3D vector [,v] is rotated by q to: Since R () v [, n ][,][ v, n ] q 1 R v q vq qvq q () q[, n ] q q [ s, v ] [ s, v ] [ ss v v, sv s v v v ] 1 1 1 1 1 1 1 1 Rv () Rv ( v ) Rv ( ) Rv ( ) v v ( nv) ( nvn ) ( v( nvn ) ) ( nv) v n( nv)(1 ) ( nv) [, v( ) n( nv) ( nv) ] [, v n( nv)(1 ) ( nv) ] 7
right hand coordinate system Examples y x z n q (,1,), n (,,1), / n (1,,), / (1,,,) q (1/,,, 1/ ) q (1/,1/,,) q (, n ) ( w, x, y, z) 8
Unit Quaternions The quaternions used for rotation have only three degrees of freedom. They all lie on the surface of a unit sphere in 4D space, forming a subgroup. Theorem: A vector v is invariant under rotations around an axis through v. Proof: The rotation operator is q=[s,cv] such that q =1. q v q [, s cv][, v][, s cv] [, s cv][ cvv, sv] [, sv c( vvv ) ] ( s c ( vv))[, v] v q v Theorem: Rotation by and - in the opposite direction are equivalent. Proof: [, n ] [, ] n Theorem: Rotation by 1 and then by (around n) is equivalent to rotation by 1 +. ( q ( q vq ) q ) ( q q ) v( q q ) Proof: 1 1 1 1 ( q q ) v( q q ) [, ] [, ] 1 1 1 1 n n 1 1 1 1 1 1 n [, n( ] [, ] 9
Quaternion to Rotation Matrix (column vectors) Rotation by unit-length quaternion: q[, n ] [ w, x, y, z] R ([, v]) q[, v] q q v n( nv)(1 ) ( nv) The first row of the equivalent rotation matrix: R([, v]) v n( nv nv nv)(1 ) ( nv nv) q x x x x x y y z z y z z y M 11 1 13 nx (1 ) M n n (1 ) n x y z M n n (1 ) n x z y 3
Quaternion to Rotation Matrix (column vectors) q [, n ] [ w, x, y, z] M 11 nx (1 ) 1 n ( ) x 1( n n n ) n ( ) x y z x 1( n n ) 1y z y z M 1 y z xy wz xz wy xy wz 1 x z yz wx xz wy yz wx 1 x y 1 31
Rotation Matrix to Quaternion Given rotation matrix M M11 M1 M13 M1 M M3 M31 M3 M33 1 The equivalent quaternion is q = [w, x, y, z] M M M 144( y z x ) 4w 11 33 1 y z xy wz M xz wy xy wz 1 x z yz wx xz wy yz wx 1 x y 1 M11 M M33 1 w M M M3 M3 4 wx x 4w M M M13 M31 4 wy y 4w M M M1 M1 4 wz z 4w 3 3 13 31 1 1 3
right hand coordinate system Examples y x z n (,1,), q (1,,,) 1 M 1 1 n (,,1), / q (1/,,, 1/ ) 1 M 1 1 n (1,,), / q (1/,1/,,) 1 M 1 1 q (, n ) ( w, x, y, z) 33
Prove Ug Quaternions and Matrices The quaternion i=(,1,,) is rotation by around the x axis. The quaternion j=(,,1,) is rotation by around the y axis. The quaternion k=(,,,1) is rotation by around the z axis. 34
Animation in VRML DEF PI PositionInterpolator { key [.5 1 ] t i keyvalue [ 5, (x(t i ) y(t i ) z(t i )) 5, 5 ]} DEF OI OrientationInterpolator { key [ 1 ] keyvalue [ 1, -1 1.57796, ]} t i (n x (t i ) n y (t i ) n z (t i ) (t i )) quaternion rotation without quaternions rotation with quaternions 35
Geodesics A great circle is a circle on the surface of a sphere that has the same circumference as the sphere, dividing the sphere into two equal hemispheres. A great circle is a spherical geodesic the shortest path between two points on a sphere. 36
Interpolating Two Orientations Orientations may be interpolated by interpolating their respective quaternions. Quaternions on a 4D sphere may be interpolated along a geodesic (the shortest path between two points on a sphere). For any u[,1], writing q(u) = (u)q +(u)q 1, and solving the following system of equations for (u) and (u): q q q, q 1 1 1 qu ( ) ( u) ( u) ( u) ( u) q, q ( u) q, q( u) ( u) ( u) q, q 1 1 q u q(u) q 1 u[,1] q() q q(1) q 1 37
q, q 1 1 q, q1 ( u) q, q 1 1 ( u) (1 u ) 1 u (1 u) ( u) ( u) Spherical Linear Interpolation (SLERP) (1 u) ( u ) qu ( ) q q1 u[,1] Equivalent to: qu ( ) q( q q) u 1 1 38
Interpolating Multiple Orientations As with linear interpolation between multiple positions, spherical linear interpolation between multiple orientations generates discontinuities in the derivative at the interpolated points. This may be solved by more elaborate interpolation schemes, which are not shortest path, similarly to splines for positions. v v 3 v q q q 1 v 1 39