UMBC Graphics for Games Quaternion Rotation UMBC Graphics for Games
Representing Rotation
Rotation Matrices Rotation can be expressed as an orthogonal matrix Every orthogonal matrix is a rotation and/or mirroring New X axis New Y axis New Z axis
Rotation Matrices Rotation can be expressed as an orthogonal matrix Every orthogonal matrix is a rotation and/or mirroring Fits with other transformation matrices Translation, Scaling, Reflection, Perspective Interpolations between rotation matrices are not rotations Interpolates endpoint positions
Euler Angles Rotate around series of axes Subject to gimbal lock Roll, Pitch, Yaw Intuitive, pitch/yaw form common for first person controllers Yaw = turn left/right Pitch = look up/down Roll = rotate around view Subject to gimbal lock First axis lines up with last axis, lose ability to rotate freely Interpolates along lines of longitude/latitude Can be weird near poles
Quaternions Extension of complex numbers Interpolations on great circle Related Geometric Algebra also works Though not as popular in games
Complex Numbers
Imaginary number i Define imaginary number i where Complex number has real and imaginary components Interpret as points on the 2D plane Conjugate: negate the imaginary part
Complex Arithmetic Addition: add components Multiplication Component algebra: Multiply magnitudes, add angles:
Complex Transformations Point Translation = addition Scale = multiply by real scalar Rotate = multiply by unit-length complex (magnitude = 1) Component form is identical to matrix rotation
Basic Rotations Pure imaginary = rotation by 90
Quaternions
Quaternion basics First created by Hamilton in 1843 for physics rotations Define orthogonal imaginary axes Multiplication order matters, positive in ijk order
Quaternion Math Like complex has real + imaginary, quaternion is real + vector Conjugate negates vector part Addition by component
Quaternion Multiplication By component Vector form
Quaternion Transformations Point is pure quaternion Translation = addition of pure quaternion Scale = multiply by real scalar Rotation = sandwiched multiply by unit quaternion and conjugate Where For one point, algebraically optimized version with cross products For more points, cheaper to convert to matrix
Basic Rotations Rotation Rotate by 0º Rotate by 180º around vector
Interpolation Interpolate along great circle between two vectors / quaternions Normalized Linear Interpolation (NLERP) Cheap, but speeds up in the middle Spherical Linear Interpolation (SLERP) Interpolate in equal-angular steps