Four different ways to represent rotation
my head is spinning...
The space of rotations
{
SO( 3) = R ∈ R 3×3
| RR = I , det( R ) = +1
T
}
Special orthogonal group(3):
Why det( R ) = ±1?
Rotations preserve distance: Rp1 − Rp2 = p1 − p2
Rotations preserve orientation: ( Rp1 ) × ( Rp2 ) = R( p1 × p2 )
The space of rotations
{
SO( 3) = R ∈ R 3×3
| RR = I , det( R ) = +1
T
}
Special orthogonal group(3):
Why it’s a group:
• R1 , R2 ∈ SO( 3) then R1 R2 ∈ SO( 3)
Closed under multiplication: if
• Has an identity: ∃I ∈ SO( 3) s.t. IR1 = R1
• Has a unique inverse…
• Is associative…
Why orthogonal:
• vectors in matrix are orthogonal
Why it’s special: det( R ) = +1 , NOT det( R ) = ±1
Right hand coordinate system
Possible rotation representations
You need at least three numbers to represent an
arbitrary rotation in SO(3) (Euler theorem). Some
three-number representations:
• ZYZ Euler angles
• ZYX Euler angles (roll, pitch, yaw)
• Axis angle
One four-number representation:
• quaternions
ZYZ Euler Angles
φ
rzyz = θ
ψ
cos φ − sin φ 0
To get from A to B:
Rz (φ ) = sin φ cos φ 0
0 1
1. Rotate φ about z axis 0
2. Then rotate θ about y axis cos θ 0 sin θ
R y (θ ) = 0 1 0
3. Then rotate ψ about z axis − sin θ 0 cos θ
cosψ − sinψ 0
Rz (ψ ) = sinψ cosψ 0
0 0 1
ZYZ Euler Angles
Remember that Rz (φ ) R y (θ ) Rz (ψ )encode the desired rotation in the pre-
rotation reference frame:
Rz (φ )= pre − rotation R post − rotation
Therefore, the sequence of rotations is concatentated as follows:
Rzyz ( φ ,θ ,ψ ) = Rz (φ ) R y (θ ) Rz (ψ )
cos φ − sin φ 0 cos θ 0 sin θ cosψ − sinψ 0
Rzyz ( φ ,θ ,ψ ) = sin φ cos φ 0 0 1 0 sinψ cosψ 0
0 0 1 − sin θ 0 cos θ 0 0 1
cφ cθ cψ − sφ sψ − cφ cθ sψ − sφ cψ cφ sθ
Rzyz ( φ ,θ ,ψ ) = sφ cθ cψ + cφ sψ − sφ cθ sψ + cφ cψ sφ sθ
−s c sθ sψ cθ
θ ψ
ZYX Euler Angles (roll, pitch, yaw)
cos φ − sin φ 0
To get from A to B:
Rz (φ ) = sin φ cos φ 0
1. Rotate φ about z axis 0 0 1
2. Then rotate θ about y axis cos θ 0 sin θ
R y (θ ) = 0 1 0
3. Then rotate ψ about x axis − sin θ 0
cos θ
1 0 0
Rx (ψ ) = 0 cosψ − sinψ
0 sinψ cosψ
Rzyx ( φ ,θ ,ψ ) = Rz (φ ) R y (θ ) Rx (ψ )
cos φ − sin φ 0 cos θ 0 sin θ 1 0 0
Rzyz ( φ ,θ ,ψ ) = sin φ cos φ 0 0 1 0 0 cosψ − sinψ
0 0 1 − sin θ 0 cos θ 0 sinψ cosψ
ZYX Euler Angles (roll, pitch, yaw)
In Euler angles, the each rotation is imagined to be represented in the
post-rotation coordinate frame of the last rotation
In Fixed angles, all rotations are imagined to be represented in the original
(fixed) coordinate frame.
ZYX Euler angles can be thought of as:
1. ZYX Euler
2. XYZ Fixed
Rzyx ( φ , θ ,ψ ) = Rz (φ ) R y (θ ) Rx (ψ )
Problems w/ Euler Angles
If two axes are aligned, then there is a “don’t care” manifold of Euler angles
that represent the same orientation
• The system loses one DOF
0 90
r1 = 90 r2 = 89
0 90
− 90
r1 − r2 = 1 , but the actual distance is 1
− 90
Problem w/ Euler Angles: gimbal lock
1. When a small change in orientation is
associated with a large change in rotation
representation
2. Happens in “singular configurations” of the
rotational representation (similar to
singular configurations of a manipulator)
3. This is a problem w/ any Euler angle
representation
Problem w/ Euler Angles: gimbal lock
Problem w/ Euler Angles: gimbal lock
Axis-angle representation
Theorem: (Euler). Any orientation, R ∈ SO( 3) , is equivalent to a rotation
about a fixed axis, ω ∈ R 3, through an angle θ ∈ [0,2π )
(also called exponential coordinates)
kx
Axis: k = ky Angle: θ
k
z
Converting to a rotation matrix:
S ( k )θ
= I + S ( k ) sin (θ ) + S ( k ) (1 − cos(θ ) )
2
Rkθ = e
= [ that equation in the book...]
Rodrigues’ formula
Axis-angle representation
Converting to axis angle:
trace( R) − 1
Magnitude of rotation: θ = k = cos −1
2
r32 − r23
1
Axis of rotation: kˆ = r13 − r31
2 sin θ
r − r
21 12
r11 r12 r13
Where:
R = r12 r22 r23
r r23 r33
13
and: trace( R ) = r11 + r22 + r33
Axis-angle representation
Axis angle is can be encoded by just three numbers instead of four:
ˆ k
If k ≠0 then k= and θ=k
k
If the three-number version of axis angle is used, then
R0 = I
For most orientations, Rk , is unique.
For rotations of 180 , there are two equivalent representations:
If k = 180 then Rk = R− k
Axis-angle problems
Still suffers from the “edge” and distance preserving problems of Euler
angles:
0
0
0 r1 − r2 = 0
r1 = 0 r2 = 0 358
179
− 179
, but the actual distance is 2
Distance metric changes as you
get further from origin.
Projection distortions
Example: differencing rotations
π 2 0
Calculate the difference between
these two rotations: k1 = 0 k2 = π 2
0 0
π2
This is NOT the right answer: k1 − k 2 = − 2
π
0
According to that, this is the π
k1 − k 2 = = 127.27
magnitude of the difference: 2
Example: differencing rotations
Convert to rotation matrices to solve this problem:
π 2 0
1
R2 = R
B T B
R2 k1 = 0 k2 = π 2
1
0 0
1 0 0 1 0 0
b
R1 = Rx ( π 2 ) = 0 cos( π 2 ) − sin ( 2 ) = 0
π 0 − 1
0 sin ( π ) cos( π 2 ) 0 1 0
2
cos( π 2 ) 0 sin ( π 2 ) 0 0 1
b
R2 = R y ( 2 ) =
π 0 1 0 = 0 1 0
− sin ( π ) 0 cos( π 2 ) − 1 0 0
2
1 0 0 0 0 1 0 0 1
B T B
1
R2 = R1 R2 = 0 0 1 0 1 0 = − 1 0 0
0 − 1 0 − 1 0 0 0 − 1 0
r32 − r23 − 1 − 1
trace( R ) − 1 −1 1 ˆ 1 1 π
2
θ = cos −1 = cos − = 23 π k= r13 − r31 = 1 k= 3
1
2 2 2 sin θ 3 3
r21 − r12 − 1 − 1
Quaternions
So far, rotation matrices seem to be the most reliable method of manipulating
rotations. But there are problems:
• Over a long series of computations, numerical errors can cause these 3x3
matrices to no longer be orthogonal (you need to “orthogonalize” them from
time to time).
• Although you can accurately calculate rotation differences, you can’t
interpolate over a difference.’
• Suppose you wanted to smoothly rotate from one orientation to another –
how would you do it?
Answer: quaternions…
Quaternions
Generalization of complex numbers: Q = q0 + iq1 + jq2 + kq3
Q = ( q0 , q )
Essentially a 4-dimensional quantity
Properties of complex ii = jj = kk = ijk = −1 jk = − kj = i
dimensions:
ij = − ji = k ki = −ik = j
Multiplication: QP = ( q0 + iq1 + jq2 + kq3 )( p0 + ip1 + jp2 + kp3 )
QP = ( p0 q0 − p ⋅ q, p0 q + q0 p + p × q )
Q * = ( q0 , q ) = ( q0 , − q )
*
Complex conjugate:
Quaternions
Invented by Hamilton in 1843:
Along the royal canal in Dublin…
Quaternions
Let’s consider the set of unit
2 2 2 2
quaternions: Q2 = q0 + q1 + q2 + q3 = 1
This is a four-dimensional hypersphere, i.e. the 3-sphere S3
The identity quaternion is: Q = (1,0)
Since: ( )
QQ* = ( q0 , q )( q0 ,−q ) = q0 q0 − q 2 , q0 q − q0 q + q × q = (1,0)
Therefore, the inverse of a unit quaternion is: Q * = Q −1
Quaternions
Associate a rotation with a unit quaternion as follows:
Given a unit axis, k̂ , and an angle, θ : (just like axis angle)
θ ˆ θ
The associated quaternion is: Qkˆ ,θ = cos , k sin
2 2
Therefore, Q represents the same rotation as −Q
Let i
(
P = 0, p
i
) be the quaternion associated with the vector
i
p
*
You can rotate a P from frame a to b: b
P = Qba PQba
a
Composition: Qca = QcbQba
−1
Inversion: Qcb = Qca Qba
Example: Quaternions
1 0
1
Rotate a
P = 0, 0 by Q= 1
,
2 2
0 0
0 1 0
1 1 1
b
P =Q PQ =
a * 1
,
2 2
0, 0 2 , − 2
0 0 0
0 12
1
= 2 , 2 0, 0
1
0 − 1
2
12 − 12 0
= 0, 0 + 0 = 0, 0
− 1 − 1 − 1
2 2
Example: Quaternions
π 2 0
Find the difference between these two axis angle
rotations: k1 = 0 k2 = π 2
0 0
0 12
sin ( π4 ) = cos( π4 ) = 1
Qcb = 1
, 1
2 2
Qba = 1
, 0
2 2
0 0
QP = ( p0 q0 − p ⋅ q, p0 q + q0 p + p × q )
0 − 12
−1
1 1
Qcb = Qca Qba = 2 , 2 2 , 0
1
0 0
θ cb = cos −1 ( 12 ) = 23 π
− 1 − 12
2 − 1
3
= 12 , 12 12 = 12 , 12 kcb = 13
1 1 1
− 2 − 2
− 3
Quaternions: Interpolation
Suppose you’re given two rotations, R1 and R2
How do you calculate intermediate rotations?
Ri = αR1 + (1 − α ) R2 This does not even result in a rotation
matrix
Do quaternions help?
αQ1 + (1 − α ) Q2 Suprisingly, this actually works
Qi =
αQ1 + (1 − α ) Q2 • Finds a geodesic
This method normalizes automatically (SLERP):
Q1 sin (1 − α ) Ω + Q2 sin αΩ
Qi =
sin Ω