Rotation representation and Interpolation CSE 35415541 Matt Boggus
Rotation representation and Interpolation CSE 3541/5541 Matt Boggus
Overview • Options for controlling orientation for Lab 4 • Interpolating between orientations
Orientation on a curve in 2 D
Orientation on a curve in 2 D
Orientation on a curve in 2 D q 1 and q 2 are orthogonal to P’(s) i. e. q 1 = Rotate(90) * P’(s) q 2 = Rotate(-90) * P’(s)
In 3 D Example using physical object
Orientation on a curve in 3 D – Frenet Frame 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]
Rotation around an arbitrary angle Y Q A X 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
Interpolating between orientations v u w
Interpolating Orientations in 3 D • Rotation matrices • Given rotation matrices Mi and time ti, find M(t) such that M(ti)=Mi v u w ux uy uz vx vy vz wx wy wz
Rotation Matrices
Flawed solution: Interpolate matrix elements • Example: M 0 is identity and M 1 is 90 o around x-axis
Another flawed solution: Interpolating between angle values
Discovering another problem with Euler (a. k. a. Fixed) Angle rotation • Any orientation can be described by composing three rotations, one around each coordinate axis • Each rotation corresponds to rotating one of the frames http: //www. fho-emden. de/~hoffmann/gimbal 09082002. pdf
Problem: Gimbal Lock • Two or more axes align resulting in a loss of rotation degrees of freedom. http: //www. fho-emden. de/~hoffmann/gimbal 09082002. pdf
Axis-Angle representation Y Q A X Z Rotate about given axis Euler’s Rotation Theorem Fairly easy to interpolate between orientations Difficult to concatenate rotations
Quaternion representation Y Q A X Same as axis-angle, but different form Still rotate about given axis Mathematically convenient form Z 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
Converting between representations Axis-Angle
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
Orientation interpolation Preliminary note: 1. Remember that 2. Affects of scale are divided out by the inverse appearing in quaternion rotation 3. 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: 1. How to take equidistant steps along orientation path? 2. How to pass through orientations smoothly (1 st order continuous) 3. And another particular to quaternions: with dual unit quaternion representations, which to use?
Interpolating quaternions Unit quaternions form set of points on 4 D 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, q 1 • the ending quaternion orientation, q 2 • the interpolant, u Still a linear order interpolation
ADDITIONAL SLIDES
More on Frenet frame and 3 D orientation setting
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
Frenet Frame tangent & curvature vector
Frenet Frame tangent & curvature vector
Frenet Frame local coordinate system Directly control orientation of object/camera Use for direction and bank into turn, especially for groundplanar 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 v=u×w w u=w × y-axis Direction vector To keep ‘head up’, use y-axis to compute over and up vectors perpendicular to direction vector If up vector supplied, use that instead of y-axis
More on Quaternions
Dual representation Dual unit quaternion representations: q = –q For Interpolation between q 1 and q 2, compute cosine between q 1 and q 2 and between q 1 and –q 2; choose smallest angle
Related methods in Unity
Rotations within Unity transform. Rotate(euler. Angles : Vector 3, relative. To : Space = Space. Self) Description Applies a rotation of euler. Angles. z degrees around the z axis, euler. Angles. x degrees around the x axis, and euler. Angles. y degrees around the y axis (in that order).
Rotations within Unity transform. Rotate(axis : Vector 3, angle : float, relative. To : Space = Space. Self) Description Rotates the transform around axis by angle degrees.
Rotations within Unity transform. Rotate. Around(point : Vector 3, axis : Vector 3, 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 Vector 3. Rotate. Towards(current : Vector 3, target : Vector 3, max. Radians. Delta : float, max. Magnitude. Delta : float) Description Rotates a vector current towards target.
Game. Object Transform fields • Try explicitly setting: – transform. forward – transform. up – transform. right
Quaternion methods • https: //docs. unity 3 d. com/Script. Reference/Qu aternion. Set. Look. Rotation. html • https: //docs. unity 3 d. com/Script. Reference/Qu aternion. Set. From. To. Rotation. html
- Slides: 47