Rotation representation and Interpolation CSE 3541 Matt Boggus
Rotation Matrices
Interpolating Orientations in 3D Rotation matrices Given rotation matrices Mi and time ti, find M(t) such that M(ti)=Mi ux vx nx uy vy ny uz vz nz u v n
Flawed Solution Interpolate each entry independently Example: M0 is identity and M1 is 90o around x-axis Is the result a rotation matrix?
Orientation Representations Rotation matrix Fixed angles: rotate about global coordinate system Euler angles: rotate about local coordinate system Axis-angle: arbitrary axis and angle Quaternions: mathematically handy axis-angle 4-tuple
Fixed Angles Any orientation can be described by composing three rotations, one around each global coordinate axis Roll, pitch and yaw (perfect for flight simulation) http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf
Gimbal Lock Two or more axes align resulting in a loss of rotation degrees of freedom. http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf
Fixed Angles in the Real World Apollo inertial measurement unit To “prevent” lock, they added a fourth Gimbal http://www.hq.nasa.gov/office/pao/History/alsj/gimbals.html
Axis-Angle Q Y A X Z Rotate about given axis Euler’s Rotation Theorem Fairly easy to interpolate between orientations Difficult to concatenate rotations
Axis-angle to rotation matrix Y Z Concatenate the following: Rotate A around z to x-z plane Rotate A’ around y to x-axis Rotate theta around x Undo rotation around y-axis Undo rotation around z-axis Q A
Quaternions (intuitionally) X Y Z Q A Same as axis-angle, but different form Still rotate about given axis Mathematically convenient form Note: in this form v is a scaled version of the given axis of rotation, A (which is a vector)
Quaternion q = s + xi + yj + zk where i, j, and k are imaginary numbers Rotation Quaternions Identity (no rotation) 1, -1 180 degrees about x-axis i, -i 180 degrees about y-axis j, -j 180 degrees about z-axis k, -k angle θ, axis (unit vector)
Quaternion Arithmetic Addition Multiplication Inner Product Length
Quaternion Arithmetic Inverse Identity Unit quaternion
Quaternion Representation and Rotation Vector Rotation
Unit Quaternion Conversions Axis-Angle
What an animator needs to know Quaternions What an animator needs to know Avoid gimbal lock Easy to rotate a point Easy to convert to a rotation matrix Easy to concatenate – quaternion multiply Easy to interpolate – interpolate 4-tuples
Rotations within Unity transform.Rotate(eulerAngles : Vector3, relativeTo : Space = Space.Self) Description Applies a rotation of eulerAngles.z degrees around the z axis, eulerAngles.x degrees around the x axis, and eulerAngles.y degrees around the y axis (in that order).
Rotations within Unity transform.Rotate(axis : Vector3, angle : float, relativeTo : Space = Space.Self) Description Rotates the transform around axis by angle degrees.
Rotations within Unity transform.RotateAround(point : Vector3, axis : Vector3, angle : float) Description Rotates the transform about axis passing through point in world coordinates by angle degrees. This modifies both the position and the rotation of the transform.
Rotations within Unity Vector3.RotateTowards(current : Vector3, target : Vector3, maxRadiansDelta : float, maxMagnitudeDelta : float) Description Rotates a vector current towards target.
Orientation along a curve
Orientation on a curve in 2D
Orientation on a curve in 2D
Orientation on a curve in 2D q1 and q2 are orthogonal to P’(u) i.e. q1 = Rotate(90) * P’(u) q2 = Rotate(-90) * P’(u)
Frenet Frame Global axes: x, y, z Local axes: u, v, w a moving (coordinate) frame that provides a coordinate system at each point of the curve that is "best adapted" to the curve near that point Global axes: x, y, z Local axes: u, v, w P(s) = parametric curve function with s on [0,1]
Frenet Frame tangent & curvature vector
Frenet Frame tangent & curvature vector
local coordinate system Frenet Frame local coordinate system Directly control orientation of object/camera Use for direction and bank into turn, especially for ground-planar curves (e.g. roads) w = P’(s) u = P’’(s) × P’(s) v = w × u
Frenet Frame – sometimes undefined
Frenet Frame – discontinuity
Other ways to control orientation Use auxiliary curve to define direction or up vector Use point P(s+ds) for direction
Direction & Up vector To keep ‘head up’, use y-axis to compute over and up vectors perpendicular to direction vector v = u × w w If up vector supplied, use that instead of y-axis u=w × y-axis Direction vector
Orientation interpolation Preliminary note: Remember that Affects of scale are divided out by the inverse appearing in quaternion rotation When interpolating quaternions, use UNIT quaternions – otherwise magnitudes can interfere with spacing of results of interpolation
Orientation interpolation Quaternions can be interpolated to produce in-between orientations: 2 problems analogous to issues when interpolating positions: How to take equidistant steps along orientation path? How to pass through orientations smoothly (1st order continuous) And another particular to quaternions: with dual unit quaternion representations, which to use?
Dual representation Dual unit quaternion representations: q = –q For Interpolation between q1 and q2, compute cosine between q1 and q2 and between q1 and –q2; choose smallest angle
Interpolating quaternions Unit quaternions form set of points on 4D sphere Linearly interpolating unit quaternions: not equally spaced
Interpolating quaternions in great arc => equal spacing
Interpolating quaternions with equal spacing where ‘slerp’, sphereical linear interpolation is a function of the beginning quaternion orientation, q1 the ending quaternion orientation, q2 the interpolant, u Still a linear order interpolation