Rotations and quaternions Jiří Chmelík, Marek Trtík PA199 ►Rotation matrix ► ►Euler angles ►Tait-Bryan angles ► ►Axis-angle representation ► ►Quaternions ►Rotations via quaternions ►Quaternion derivative Outline Rotation matrix 3 Euler angles 4 “Line of nodes” Euler angles 5 “Line of nodes” Euler angles 6 “Line of nodes” Euler angles 7 “Line of nodes” Euler angles 8 “Line of nodes” Euler angles 9 Euler angles 10 Euler angles 11 Euler angles 12 Euler angles 13 Euler angles 14 More intuition is in video: [5] Euler angles: gimbal lock 15 ►We can use 3 angles to express any orientation of an object in 3D space: public class Orientation { float alpha; float beta; float gamma; }; ►Pros: ►Low memory footprint. ►Easy to understand. ►Cons: ►Suffers from the gimbal lock. ►Slow conversion to matrix representation (sin and cos for each angle). Euler angles representation 16 Tait-Bryan angles 17 Axis-angle rotation 18 Axis-angle rotation 19 Axis-angle rotation 20 Axis-Angle to rotation Matrix 21 Linear interpolation (lerp) 22 Spherical linear interpolation (slerp) 23 ►We can use axis-angle to express any orientation of object in 3D space. public class Orientation { float angle; Vector3 unitAxis; }; ►Pros: ►Fast conversion to matrix representation (sine and cosine for one angle). ►We can use lerp and slerp. ►Easy to understand. ►Low memory footprint. ►Cons: ►Complicated composition of rotations (often solved via other rep.). Axis-angle representation 24 Quaternions 25 Quaternions 26 Rotation via quaternion 27 TADYà Rotation via quaternion 28 Quaternions and other representations 29 Linear interpolation (lerp) 30 Spherical linear interpolation (slerp) 31 Quaternion derivative 32 Quaternion derivative 33 Quaternion derivative 34 ►We can use quaternions to express any orientation of object in 3D space. public class Orientation { // Equals to a quaternion q=(s,u), |q|=1. float s; // the scalar part Vector3 u; // the vector part }; ►Pros: ►Low memory footprint. ►Fast conversion to rotation matrix (no need to compute cosine & sine). ►Fast composition of rotations (just multiply the quaternions). ►We can use lerp and slerp. ►Cons: ►Less human readable. Quaternion representation 35 ►There is no single winner – each representation has pros and cons. ► ►Examples: ►When specifying a rotation along a coordinate axis (e.g., world Z), then Euler angles are a good choice. ►When specifying a rotation along non-coordinate axis, then axis-angle representation is a good choice. ►When composing rotations of some joint of a skeleton, then quaternions can do it quickly. ►When rotations must be composed with other transformations, then use matrix representation. ► ►Game engine should provide all representations and conversions between them. What representation to use? 36 ►[1] D.M.Mount; Lecture notes CMSC 425 Game Programming; University of Maryland, 2016. ►[2] E.B.Dam,M.Koch,M.Lillholm; Quaternions, Interpolation and Animation; TechnicalReport DIKU-TR-98/5, University of Copenhagen, 1998. ►[3] M.C.Nechyba; Lecture notes EEL6667: Kinematics, Dynamics and Control of Robot Manipulators - Introduction to quaternions; 2003, https://mil.ufl.edu/nechyba/www/__eel6667.f2003/course_materials.html. ►[4] Y.-B. Jia; Lecture notes (Com S 477/577 Notes) Quaternions; 2018. ►[5] Euler angles: https://www.youtube.com/watch?v=A6lf8t9WXn8 References 37