15 - Rotation Interpolation

advertisement
Rotation representation and
Interpolation
CSE 3541
Matt Boggus
0
0
1
0 cos   sin  

0 sin   cos 

0
0
0
Rotation
Matrices
 cos 
 0

 sin  

 0
0
0
0

1
0 sin   0
1
0
0
0 cos  0

0
0
1
cos   sin  
 sin   cos 

 0
0

0
 0
0 0
0 0
1 0

0 1
Interpolating Orientations in 3D
• Rotation matrices
• Given rotation matrices Mi and time ti,
find M(t) such that M(ti)=Mi
y
v
u
x
z
n
ux uy uz
M  vx vy vz
nx ny nz
Flawed Solution
• Interpolate each entry independently
• Example: M0 is identity and
M1 is 90o around x-axis
0
0 
1 0 0  1 0 0 
1
Interpolate ( 0 1 0  , 0 0 1  )  0 0.5 0.5 

 



0 0 1  0 1 0 
0 0.5 0.5 
• 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
 A
 x
Y
Q
A
y
z 
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
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
Quaternions (intuitionally)
Rot 
Y
  


 sin( ) * A
A   cos
2
 2

Q
A
X
Same as axis-angle, but different form
Still rotate about given axis
Mathematically convenient form
s
q
v
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
s1  s2
v1  v2   s1 v1   s2
Multiplication
q1q2  s1s2  v1  v2
Inner Product
Length
s2v1  s1v2  v1  v2 
q1  q2  s1s2  v1  v2
q  qq
v2 
Quaternion Arithmetic
Identity
1
1
q 
Inverse
q
2
s
qq 1  q 1q  1
 pq 
1
Unit quaternion
1
 v
0
q p
qˆ 
q
q
1
0 0
Quaternion Representation and Rotation
Vector
Rotation
0
v
v'  Rot q (v)  qvq1
Unit Quaternion Conversions
Rot s
x
y
1  2 y 2  2 z 2
2 xy  2 sz
2 xz  2sy 


2
2
1 2x  2z
2 yz  2 sx 
z    2 xy  2 sz
2
2
 2 xz  2 sy
2 yz  2sx 1  2 x  2 y 

Axis-Angle
  2 cos 1 ( s)
( x, y , z )  v / v
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
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
P (u )  UMB
P ' (u )  U ' MB
P ' ' (u )  U ' ' MB

U '  3u
Uu
3
u
2
2

u 1
2u 1 0
U ' '  6u 2 0 0

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
Orientation interpolation
Preliminary note:
Rot q (v)  Rot kq (v)
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:
q  (1  k )q1  kq2
2 problems analogous to issues when interpolating positions:
1. How to take equidistant steps along orientation path?
2. How to pass through orientations smoothly (1st order continuous)
3. And another particular to quaternions: with dual unit quaternion
representations, which to use?
Dual
representation
Rot q (v)  Rot kq (v)
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
sin( 1  u )
sin u
slerp (q1 , q2 , u ) 
q1 
q2
sin 
sin 
where
q1  q2  cos
‘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
Download