Fundamentals of Computer Animation Orientation and Rotation University of Calgary GraphicsJungle Project CPSC 587 5 page
Motivation Finding the most natural and compact way to present rotation and orientations Orientation interpolation which result in a natural motion A closed mathematical form that deals with rotation and orientations (expansion for the complex numbers) University of Calgary GraphicsJungle Project CPSC 587 5 page
Rotation Matrix A general rotation can be represented by a single 3x3 matrix Length Preserving (Isometric) Reflection Preserving Orthonormal R = u v w x x x u v w y y y u v w z z z University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Object Representation Define object in world space Object space data Scale Rotation Translation Desired operations Interpolation between transformations Concatenation of one transformation after another Handle scale, rotation, translation, independently Rotation deserves special attention! University of Calgary GraphicsJungle Project CPSC 587 5 page 4
University of Calgary GraphicsJungle Project CPSC 587 5 page 5 Rotation Matrix Representation = z y x z y x z y x w w w v v v u u u R = = = cos sin sin cos ) ( cos sin sin cos ) y - roll( cos sin sin cos ) ( 3 3 3 3 3 roll z roll x This could be the Upper 3x3 of a 4x4 homogeneous matrix Pure rotation is special orthogonal inverse = transpose
Repeated Rotations: Error Management Method M = create_rotation_matrix( ) Object = apply M to Object Method D = create_rotation_matrix( ) M create_rotation_matrix() M = D M Object = apply M to object Method 3 = + M = create_rotation_matrix() Object = apply M to object <= repeat {p = Mp} round off error accumulates <= repeat {p = Mp; M=DM} round off error accumulates in M no longer ortho-normal (orthogonal matrix) <= repeat error accumulates in but M orthogonal University of Calgary GraphicsJungle Project CPSC 587 5 page 6
Rotation Matrices - Can t interpolate rotation matrices - 9 o z-axis -9 o z-axis?? University of Calgary GraphicsJungle Project CPSC 587 5 page 7
Orientation Representation orientation University of Calgary GraphicsJungle Project CPSC 587 5 page 8
Interpolation O O.5 O University of Calgary GraphicsJungle Project CPSC 587 5 page 9
Other Representations alternative representations: Fixed Angle Euler Angle Axis Angle Quarternians University of Calgary GraphicsJungle Project CPSC 587 5 page
Fixed Angle Representation Angles used to rotate about fixed axes Orientations are specified by a set of 3 ordered parameters that represent 3 ordered rotations about fixed axes, e.g. first about x, then y, then z (x-y-z). Many possible orderings, don t have to use all 3 axes. x-x-y multiple rotations around same axis redundant University of Calgary GraphicsJungle Project CPSC 587 5 page
Fixed Angle Representation A rotation of,45, 9 would be written as Rz(9), Ry(45), Rx() since we want to first rotate about x, y, z. It would be applied then to the point P. RzRyRx P Problem occurs when two of the axes of rotation line up on top of each other. This is called Gimbal Lock University of Calgary GraphicsJungle Project CPSC 587 5 page
University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Concatenation O O University of Calgary GraphicsJungle Project CPSC 587 5 page 4
Fixed Angle Interpolation (,9,) to (9,,9) (,,) (,9,) (9,,9) University of Calgary GraphicsJungle Project CPSC 587 5 page 5
Gimbal Lock A 9 degree rotation about the y axis essentially makes the first axis of rotation align with the third. Incremental changes in x,z produce the same results you ve lost a degree of freedom i.e. rotating around z produces the same effect as rotate around x. (see program) since x is now z University of Calgary GraphicsJungle Project CPSC 587 5 page 6
Gimbal Lock Phenomenon of two rotational axis of an object pointing in the same direction. Simply put, it means your object won't rotate in an obvious fashion (this applies to interpolation too). University of Calgary GraphicsJungle Project CPSC 587 5 page 7
Euler Angles Euler Angle Rotation: Rotation around the rotating (local) axes. The axes of rotation are the axes of the local coordinate system fixed to the object. A general rotation is a combination of three elementary rotations: around the x-axis (x-roll), around the y-axis (y-roll) and around the z-axis (z-roll). University of Calgary GraphicsJungle Project CPSC 587 5 page 8
University of Calgary GraphicsJungle Project CPSC 587 5 page 9 Euler Angles and Rotation Matrices = = = cos sin sin cos ) ( cos sin sin cos ) y - roll( cos sin sin cos ) ( 3 3 3 3 3 roll z roll x + + = ),, ( 3 3 3 3 3 3 3 3 3 3 3 c c c s s s c s s c s c c s c c s s s s c c s s s s c c c R Need global
Euler Angles An Euler angle representation: e.g. x-y-z ordering specified as α,β,γ R(α) x-axis rotation R(β) y-axis rotation around y-axis of rotated local coordinate system. R is rotation around rotated frame, to implement the y-axis rotation: R y (β)r x (α)= R x (α)r y (β)r x (-α)r x (α)=r x (α)r y (β) implement with global axes rotations so Euler is identical to fixed angle system with reverse order of rotations. (see page 57). University of Calgary GraphicsJungle Project CPSC 587 5 page
Euler Angles Show that Euler angle ordering is equivalent to reverse ordering in fixed angles Use (z,y,x) Y y P = R z ( )P P = R z ( )R y ( )R z ( ) P P = R z ( )R y ( )R z ( )R z ( )P P = R z ( )R y ( )P P = R z ( )R y ( )R x ( 3 )R y ( )R z ( ) P P = R z ( )R y ( )R x ( 3 )R y ( )R z ( )R z ( )R y ( )P P = R z ( )R y ( )R x ( 3 )P Z z x X and so has the same problems University of Calgary GraphicsJungle Project CPSC 587 5 page
Gimbal Lock (again!) Rotation by 9 o causes a loss of a degree of freedom z z z y π/ y 3 y x x x x x University of Calgary GraphicsJungle Project CPSC 587 5 page
Euler angles interpolation y π x z x-roll π y x z R(,,),,R(πt,,),,R(π,,) t [,] Same problem as fixed angle inerpolation. y π x z y-roll π y π x z z-roll π y x z R(,,),,R(,πt, πt),,r(,π, π) University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Euler Angles Interpolation Unnatural movement! University of Calgary GraphicsJungle Project CPSC 587 5 page 4
Goal Find a parameterization in which a simple steady rotation exists between two key orientations moves are independent of the choice of the coordinate system University of Calgary GraphicsJungle Project CPSC 587 5 page 5
Axis Angle Interpolation (,n) defines an angular displacement of about an axis n Y A A X Z B=A x A cos - (A A ) = A.A B=A x A A K =R B (k.)a K =(-k) +k University of Calgary GraphicsJungle Project CPSC 587 5 page 6
Angle and Axis Any orientation can be represented by a 4-tuple angle, vector(x,y,z) where the angle is the amount to rotate by and the vector is the axis to rotate about Can interpolate the angle and axis separately No gimbal lock problems! But, can t efficiently compose rotations must convert to matrices first! University of Calgary GraphicsJungle Project CPSC 587 5 page 7
Quaternions? Extend the concept of rotation in 3D to 4D. Avoids the problem of "gimbal-lock" and allows for the implementation of smooth and continuous rotation. In effect, they may be considered to add a additional rotation angle to spherical coordinates ie. Longitude, Latitude and Rotation angles A Quaternion is defined using four floating point values w x y z. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle. University of Calgary GraphicsJungle Project CPSC 587 5 page 8
Quaternions q =[s,v]=[s,x,y,z] Α Has the same information as axis-angle but in a more computational-friendly form (cos(/),sin(/)*a) University of Calgary GraphicsJungle Project CPSC 587 5 page 9
How do quaternions relate to 3D animation? Solution to "Gimbal lock" Instead of rotating an object through a series of successive rotations, a quaternion allows the programmer to rotate an object through a single arbitary rotation axis. Because the rotation axis is specifed as a unit direction vector, it may be calculated through vector mathematics or from spherical coordinates ie (longitude/latitude). Quaternions interpolation : smooth and predictable rotation effects. University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Quaternions Definition Extension of complex numbers 4-tuple of real numbers s,x,y,z or [s,v] s is a scalar v is a vector Same information as axis/angle but in a different form Can be viewed as an original orientation or a rotation to apply to an object University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Quaternions Math - Definitions Quaternion Addition q = [s,v ] q = [s,v ] q +q = [s +s, v +v ] Quaternion multiplication associative (q.q ).q 3 = q.(q.q 3 ) Quaternion multiplication non commutative q = [s,v ] q = [s,v ] q.q = [s s v v, s v + s v + v x v ] q.q q.q University of Calgary GraphicsJungle Project CPSC 587 5 page 3
Quaternions Math Magnitude University of Calgary GraphicsJungle Project CPSC 587 5 page 33
Quaternion Rotation To rotate a vector, v using quaternion math represent the vector as [,v] represent the rotation as a quaternion, q v = Rot(v) = q.v.q - Unit quarternian rotated around axis (x,y,z) by amount q = Rot,(x,y,z) = [cos(/), sin(/).(x,y,z)] University of Calgary GraphicsJungle Project CPSC 587 5 page 34
Quaternion Rotation v = Rot(v)=q.v.q - Unit quarternian rotated around axis (x,y,z) by amount q = Rot,(x,y,z) =[cos(/), sin(/).(x,y,z)] Rotation by quarternian p followed by rotation by q on vector v: v is the quarternian [,v] Rot q (Rot p (v)) = q.(p.v.p - ).q - = ((qp).v.(qp) - ) =Rot qp (v) University of Calgary GraphicsJungle Project CPSC 587 5 page 35
Inverse Quaternion Rotation Inverse quarternian q - represents rotation in the opposite direction: Rot - (Rot(v)) = q -.(q.v.q - ).q= v Magnitude is divided out by multiplying by inverse (q.v.q - ) thus scalar multiples of quarternian represents same rotation as unit quarternian (similar idea as with homogeneous point representation). note that real part (scalar part) is R(z v z - )= R ( v z z - )=R(v )= v = [, v] University of Calgary GraphicsJungle Project CPSC 587 5 page 36
(-ve) Quaternion Rotation v = Rot(v)=q.v.q - Unit quarternian rotated around axis (x,y,z) by amount q = Rot,(x,y,z) = [cos(/), sin(/).(x,y,z)] -q = Rot -,-(x,y,z) =[cos(-/), sin(-/).(-(x,y,z))] =[cos(/), -sin(/).(-(x,y,z))] =[cos(/), sin(/).((x,y,z))] -q = q = Rot,(x,y,z) University of Calgary GraphicsJungle Project CPSC 587 5 page 37
Quaternion to Rotation Matrix Q = ( X Y Z W ) M = Y XY XZ + Z ZW YW XY ZW X Z YZ + XW XZ YZ X + YW XW Y University of Calgary GraphicsJungle Project CPSC 587 5 page 38
Quaternions as Rotations Rotation of P=(,r) about the unit vector n by an angle using the unit quaternion q=(s,v) R [ P] = qpq = (,( s v v) r + v( v r) + sv r) q but q=(cos½, sin½ n) where n = R q [ P] = (, (cos sin ) r ( n r)cos sin ) = (, cos r + ( cos ) + n( n r)sin n ( n r) + + ( n r)sin ) University of Calgary GraphicsJungle Project CPSC 587 5 page 39
University of Calgary GraphicsJungle Project CPSC 587 5 page 4 Quaternions as Rotations Concatenating rotations rotate using q and then using q is like rotation using q *q ) * *( )* * ( ) * *( )* * ( )* * * *( = = q q P q q q q P q q q q P q q
Rotations in Reality It s easiest to express rotations in Euler angles or Axis/angle We can convert to/from any of these representations Choose the best representation for the task input:euler angles interpolation: quaternions composing rotations: quaternions, orientation matrix University of Calgary GraphicsJungle Project CPSC 587 5 page 4
University of Calgary GraphicsJungle Project CPSC 587 5 page 4