Rotation in The Space: 1 Euler Angles
Rotation in The Space: 1 Euler Angles
Yan-Bin Jia
The position of a point after some rotation about the origin can simply be obtained by mul-
tiplying its coordinates with a matrix. One reason for introducing homogeneous coordinates is to
be able to describe translation by a matrix so that multiple transformations, whether each is a
rotation or a translation, can be concatenated into one described by the product of their respective
matrices. However, in some applications (such as spaceship tracking), we need only be concerned
with rotations of an object, or at least independently from other transformations. In such a sit-
uation, we often need to extract the rotation axis and angle from a matrix which represents the
concatenation of multiple rotations. The homogeneous transformation matrix, however, is not well
suited for the purpose.
1 Euler Angles
A rigid body in the space has a coordinate frame attached to itself and located often at the center
of mass. This frame is referred to as the body frame or local frame. The position, orientation, and
motion of the body can be described using the body frame relative to a fixed reference frame, called
the world frame.
zB
xB
z
yB
Body Frame
y
x World Frame
The rigid body has six degrees of freedom: its position given by the x, y, z coordinates of its
center of mass (i.e., the origin of the local frame) in the world frame, and its orientation described
∗
The material is partially based on Chapters 3–6 of the book [2]
1
Roll
Pitch
Yaw
by three angles of rotation of its body frame from the world frame. To describe this rotation, one
choice is to use three angles respectively about the x-, y-, and z-axes of the world frame. A more
convenient choice, from the perspective of the rotating body, is to use three angles about the axes
of the body frame. The latter three angles are called Euler angles.
For example, an aircraft in flight can perform three independent rotations: roll, about an axis
from nose to tail; pitch, nose up or down about an axis from wing to wing; and yaw, nose left or
right about an axis from top to bottom.
There are several conventions for Euler angles, depending on the axes about which the rotations
are carried out. Here we introduce the Z-Y -X Euler angles. The body frame starts in the same
orientation as the world frame. To achieve its final orientation, the first rotation is by an angle
φ, about the body z-axis, the second rotation by an angle θ ∈ [0, π] about the body y-axis, and
the third rotation by an angle ψ about the body x-axis. Here, φ, θ, and ψ correspond to as yaw,
pitch, and roll, respectively. The three rotations are illustrated in Figure 3, where x′B -yB
′ -z ′ and
B
′′ ′′ ′′
xB -yB -zB are the two intermediate configurations of the body frame xB -yB -zB .
p′′ p′ p
z, zB′′ zB′′
zB′ zB′ yB
φ θ
zB
yB′′ yB′ , yB′′ yB′
y ψ
x
x′′B x′′B
x′B x′B , xB
Figure 3: Z-Y -X Euler angles φ (yaw), θ (pitch), ψ (roll). Here, p, p′ , and p′′ are the same point of
coordinates in the frames xB -yB -zB , x′B -yB
′ ′
-zB , and x′′B -yB
′′ ′′
-zB , respectively.
Now we derive a single 3 × 3 matrix to combines the effects of the three rotations. The matrix,
through multiplication, will map a point p with its coordinates expressed in the body frame xB -
yB -zB to its coordinates in the world frame x-y-z. Let us determine these world coordinates by
considering the four frames backward: xB -yB -zB , x′B -yB
′ -z ′ , x′′ -y ′′ -z ′′ , and x-y-z. Since the frame
B B B B
2
xB -yB -zB is obtained from the frame x′B -yB
′ -z ′ by a rotation about the x′ -axis through an angle
B B
ψ, the coordinates of p in the latter frame is
p′ = Rotx (ψ)p.
Thus the transformation matrix associated with the Z-Y -Z Euler angles are
Euler angles are defined in terms of three moving axes. Singularities happen when two of
these axes coincide. Consider the Z-X-Z Euler angles α, β, γ with β = 0. Here, the first and
the third rotations are about the same axis. All the Euler angles (α, 0, γ) with the same α + γ
value thus describe one rotation. Namely, one degree of freedom is lost. Linear interpolation
from one orientation to another is not well-behaved. Imagine, when the latitude and longitude
values are interpolated. What will happen when latitude goes towards 90 degrees to reach the
north pole? All longitude values there make no difference as they end up describing the same
point! This is a phenomenon referred to as “gimbal lock”, drawing its name from certain ori-
entation with three nested moving gimbals in which two of the three axes become collinear —
restricting the available rotations to only two axes. (Watch a nice video tutorial on gimbal lock at
https://www.youtube.com/watch?v=zc8b2Jo7mno).
The above singularity issue with Euler angles is because they form a 3D box [0, 2π]3 , while
the rotations constitute a 3D projective space. The mapping between the two spaces cannot be
“continuous both ways” (or, strictly speaking, a homeomorphism1 ).
3
axis back to its original orientation. Now let us present a simpler approach with direct geometric
meaning.
Let l̂ = (lx , ly , lz )T be the unit vector along the rotation axis. To obtain the resulting v ′ from
the rotation, we decompose v into two parts: one along v̂ and the other in the plane Π containing
the origin and perpendicular to v̂:
vk = (v · l̂)l̂, (2)
v⊥ = v − vk
= v − (v · l̂)l̂. (3)
As shown in Figure 4, the component v k is not affected by rotation. We need only determine the
vector v ′⊥ that results from applying the same rotation to v ⊥ .
w
v ′⊥
v⊥
θ vk v′
l̂
θ
v w
v⊥ v ′⊥
x y
w = l̂ × v ⊥ = l̂ × v. (4)
It is easy to see that v ⊥ , w, l̂ are the axes of a right-handed system. Since l̂ is orthogonal to v ⊥ ,
v ⊥ and w have the same length. The vector v ′⊥ lies in the plane Π, and has the form
v ′ = v k + v ′⊥
= (v · l̂)l̂ + v ⊥ cos θ + w sin θ (by (2) and (5))
= (v · l̂)l̂ + (v − (v · l̂)l̂) cos θ + (l̂ × v) sin θ (by (3) and (4))
= v cos θ + (l̂ × v) sin θ + l̂(l̂ · v)(1 − cos θ). (6)
4
Note that
cos θ 0 0
v cos θ = 0 cos θ 0 v;
0 0 cos θ
0 −lz ly
l̂ × v = lz 0 −lx v;
−ly lx 0
T
l̂(l̂ · v) = (l̂l̂ )v
2
lx lx ly lx lz
= ly lx ly2 ly lz v.
lz lx lz ly lz2
Substituting the above into (6), we express v′ as the product of the following 3 × 3 rotation matrix
with v:
lx lx (1 − cos θ) + cos θ lx ly (1 − cos θ) − lz sin θ lx lz (1 − cos θ) + ly sin θ
Rotl̂ (θ) = lx ly (1 − cos θ) + lz sin θ ly ly (1 − cos θ) + cos θ ly lz (1 − cos θ) − lx sin θ . (7)
lx lz (1 − cos θ) − ly sin θ ly lz (1 − cos θ) + lx sin θ lz lz (1 − cos θ) + cos θ
3 Rotation Matrix
We have seen the use of a matrix to represent a rotation. Such a matrix is referred to as a rotation
matrix. In this section we look at the properties of rotation matrix. Below let us first review some
concepts from linear algebra.
3.1 Eigenvalues
An n × n matrix A is orthogonal if its columns are unit vectors and orthogonal to each other,
namely, if AT A = In , where In is the n × n identity matrix. An orthogonal matrix has determinant
det(A) = ±1.
A complex number λ is called the eigenvalue of A if there exists a vector x 6= 0 such that
Ax = λx. It tells whether the vector x is stretched or shrunk or reversed or left unchanged —
when it is multiplied by A. The vector x is called an eigenvector of A associated with the eigenvalue
λ. The set of all eigenvalues is called the spectrum of A.
The matrix A has exactly n eigenvalues (multiplicities included). They are the roots of the nth
degree polynomial det(A − λIn ), called the characteristic polynomial. Let λ1 , . . . , λk be the distinct
eigenvalues of this polynomial, then
Example 1. The diagonal matrix aIn has the characteristic polynomial (a − λ)n . So a is the only eigenvalue
while every vector x ∈ C n , x 6= 0 is an eigenvector. Both algebraic and geometric multiplicities of a are n.
5
Example 2. The nth order matrix
a 1 0 ··· 0
0 a 1 ··· 0
.. .. ..
.. ..
A=
. . . .
.
..
0 0 0 . 1
0 0 0 ··· a
also has the characteristic polynomial (a − λ)n and a as its only eigenvalue. The algebraic multiplicity of a
is n. However, the rank of A − aIn is n − 1; hence the geometric multiplicity of a is n − (n − 1) = 1.
The product of the n eigenvalues equals the determinant of A. The sum of the n eigenvalues
equals the sum of the n diagonal entries; this number is called the trace of A and denoted Tr(A).
The matrix A is invertible if and only if it does not have a zero eigenvalue. A symmetric matrix
has real eigenvalues. A symmetric and positive definite matrix has positive eigenvalues.
Theorem 1 A 3 × 3 matrix describes a rotation about some axis through the origin if and only if
it is orthogonal and has determinant 1.
Proof (⇒) We first show that any rotation matrix R is orthogonal and det(R) = 1. Let l be
the corresponding rotation axis and θ the angle of rotation about the axis. The inner product of
two vectors, say, v1 and v 2 , must be preserved under the rotation; namely,
(Rv 1 )T (Rv 2 ) = v T1 v 2 .
R T R − I3 = 0 and thus R T R = I3 .
we infer that det(R) must be 1 or −1. But a rotation preserves the right-handedness of a coordinate
frame, so we cannot have det(R) = −1. For example, the diagonal matrix with diagonal entries
1, 1, and −1 would describe a reflection about the x-y plane instead of a rotation. We have thus
shown that det(R) = 1.
(⇐) Suppose R is a 3 × 3 orthogonal matrix with determinant 1. We want to show that it
represents a rotation. First, we show that there exists a vector u such that Ru = u. This vector
6
will be along the rotation axis. It suffices to establish that the matrix R has an eigenvalue of 1,
which is true if and only if det(R − I3 ) = 0. We have
det(R − I3 ) = det(RT ) det(R − I3 )
= det(RT R − RT )
= det(I3 − RT ) (A orthogonal)
T
= det((I3 − R) )
= det(I3 − R)
= − det(R − I3 ).
Thus det(R − I3 ) = 0. Next, we show that the plane containing the origin and orthogonal to u
maps to itself under the rotation. Consider an arbitrary vector l in this plane, i.e., lT u = 0. The
vector Al is orthogonal to u because
(Rl)T u = lT RT Ru
= lT Iu
= lT u
= 0.
Finally, the inner product of two vectors v 1 and v2 is invariant under the transformation because
R is orthogonal. Therefore, the lengths of v1 and v 2 and the angles between them are preserved
under R. Hence the transformation represented by R is a rotation.
A rotation about an axis not through the origin cannot be simply represented by a 3 × 3
orthogonal matrix with determinant 1. Below we reason this by contradiction. First, let l be the
direction of the axis, and b be a point on the axis. Since the origin is not on the axis, b 6= 0. Every
point p ∈ R3 is transformed into R(p − b) + b, where R 6= I3 is a rotation matrix. Assume that
the transformation is equivalent to some rotation about the origin. Then there exists a rotation
matrix R′ such that
R(p − b) + b = R′ p. (8)
For any q 6= p, it also holds
R(q − b) + b = R′ q. (9)
Now, subtract (9) from (8):
R(p − q) = R′ (p − q).
Since p and q are arbitrary points, the vector p − q is arbitrary. For the above equation to always
hold, R = R′ must be true. Equation (8) now reduces to
Rb = b,
which implies that the vector b (from the origin) is aligned with the rotation axis l, in other words,
l passes through the origin. Thus, a contradiction.
Two successive rotations about the same axis in R3 is equivalent to one rotation about this axis
through an angle which is the sum of the two rotation angles. Even if they are not about the same
axis through the origin, their composition is still a rotation through some angle about some axis.
The reason is that the product of their rotation matrices, each orthogonal with determinant 1, is
still orthogonal with determinant 1. Thus, by Theorem 1 the product matrix describes a rotation.
To state this formally, the composition of any two rotations is equivalent to a rotation.
7
3.3 Recovery of Rotation Axis and Angle
Consider the following orthogonal matrix with determinant 1:
r11 r12 r13
R = r21 r22 r23 .
r31 r32 r33
Theorem 1 says that it represents a rotation about some axis l through the origin. We can extract
the Euler angles φ, θ, and ψ based on the form (1). How to find the axis of rotation? It follows from
the proof of Theorem 1 that l must be an eigenvector of R which corresponds to the eigenvalue 1.
Namely,
(R − I3 )l = 0,
from which we can obtain a solution vector by setting one of the non-zero components in l to 1.
Note that l is also an eigenvector of RT for
RT l = RT Rl
= I3 l
= l.
We have
0 = (R − RT )l
0 q3 −q2 v1
= −q3 0 q1 v2
q2 −q1 0 v3
q1 v1
= q2 × v2 (10)
q3 v3
where
q1 = r23 − r32 ,
q2 = r31 − r13 ,
q3 = r12 − r21 .
The last equation above implies that the rotation axis l must be in the same direction as q =
(q1 , q2 , q3 )T . We simply let
r23 − r32
l = q = r31 − r13 . (11)
r12 − r21
Having determined the rotation axis l, we look at how to recover the rotation angle. If the
rotation happens to be about the z-axis through an angle θ, then we have the rotation matrix
cos θ − sin θ 0
R = Rotz (θ) ≡ sin θ cos θ 0 .
0 0 1
8
And the rotation angle θ satisfies cos θ = r11 . We can also utilize the trace
and obtain
Tr(R) − 1
cos θ = , (12)
p2
sin θ = ± 1 − sin2 cos θ
r
3 − Tr(R)2 + 2Tr(R)
= ± . (13)
4
The sign of sin θ must agree with that of r21 .
In fact, the solution of θ from (12)–(13) generalizes to the situation with an arbitrary rotation
axis. To see this, we use the old trick of applying a sequence of rotations, represented by a matrix
Q, to transform the axis l into the z-axis. Then we carry out the rotation about the z-axis through
the angle θ. Finally, we apply a sequence of reverse rotations QT to transform the z-axis back to
l. The rotation matrix is represented as
The trace function is commutative, that is, Tr(CD) = Tr(DC) for any two square matrices of
the same dimensions.2 This property allows us to derive the following from (14):
Tr(R) = Tr QT Rotz (θ)Q
T
= Tr Q Rotz (θ) Q
T
= Tr Q Q Rotz (θ)
T
= Tr QQ Rotz (θ)
= Tr I3 Rotz (θ)
= Tr Rotz (θ)
= 1 + 2 cos θ.
Hence the rotation angle θ still satisfies equation (12) when the rotation axis is arbitrary. How
do we determine the sign in (13)? First, we normalize the rotation axis l from (11) and obtain a
unit vector l̂ = (lx , ly , lz ). The rotation about l̂ through an angle θ is given by the matrix in (7).
Comparing an off-diagonal element in the matrix R, say r21 , with its corresponding entry in Rotl̂ (θ)
gives us
r21 − lx ly (1 − cos θ)
sin θ =
lz
2r21 − lx ly (3 − Tr(R))
= . (15)
2lz
2
The proof is directly based on the definition of trace.
9
The angle θ ∈ [0, 2π) of rotation is thus completely determined from (12) and (15).
The rotation about the axis l through θ can also be viewed as one about the axis −l through
−θ, yielding a second solution.
Example 3. Here we describe an application of rotations in tracking. Consider a remote object, such as
an aircraft, which is being tracked from a station on the earth. We define a local coordinate system at the
station with the xy-plane being the tangent plane to the earth. The x- and y-axes point in the directions
of the North and East, respectively, and the z-axis points toward the center of the earth. The coordinate
system is drawn in Figure 5.
remote
x′ object
x (north) tangent
plane
α
(heading) β
(elevation)
y (east)
station
y′
z z′
earth
The heading α is the angle in the tangent plane between the North and the projection of the direction
to the remote object being tracked. The elevation is the angle between the tangent plane and the direction
to the object. The tracking transformation is a rotation about the z-axis through the angle α, followed
by a rotation about the new y-axis through the angle β. After these two rotations, the x-axis is pointing
toward the object. The tracking coordinate system is made up of the new x′ -, y ′ -, and z ′ -axes after the two
rotations.
Let R be the 3 × 3 matrix to represent the composite rotation; it relates the tracking coordinate system
to the station’s coordinate system. Namely, a point p = (px , py , pz )T in the (re-oriented) tracking frame is
Rp in the station’s frame. Then we have
10
cos α − sin α 0 cos β 0 sin β
= sin α cos α 0 0 1 0
0 0 1 − sin β 0 cos β
cos α cos β − sin α cos α sin β
= sin α cos β cos α sin α sin β .
− sin β 0 cos β
This composite tracking transformation can be represented as an equivalent rotation through some angle θ
about some axis l. By (11) we know that the rotation axis is given by
sin α2 sin β2
sin α sin β
l = − cos α sin β − sin β ≡ − cos α2 sin β2 . (16)
− sin α cos β − sin α α β
− sin 2 cos 2
Let l̂ = (lx , ly , lz ) be the normalization of l. By (12) and (15) the angle of rotation satisfies the following
equations:
cos α cos β + cos α + cos β − 1
cos θ = ,
2
2 sin α cos β − lx ly 3 − Tr(A)
sin θ = .
2lz
The domain for the tracking angles is α ∈ (−π, π] and β ∈ [− π2 , π2 ]. As β increases from π2 −ǫ to π2 +ǫ, for
small ǫ, α instantaneously jumps to α + π. For this reason, (α, π2 ) is a singular point, and the phenomenon
is gimbal lock.
11
The matrix
R = (û, v̂, ŵ)
describes the rotation of the u-v-w frame from the x-y-w frame. It maps the coordinates of a point
in the first frame to its coordinates in the second frame. This is very useful when considering the
u-v-w as attached to a body that is rotating.
Take an arbitrary point, say q = (qx , qy , qz )T , in the x-y-z frame. What are its coordinates
q ′ = (qu , qv , qw )T when expressed in the u-v-w frame? From q = Rq′ we immediately have that
q ′ = R−1 q = RT q.
12
ℓ
Rc + b
bk
b c = Rc + b⊥
b⊥
Rc
Figure 6: Any rigid body transformation is equivalent to a rotation about some axis, followed by a trans-
lation along the same axis.
As shown in Figure 6, c is the perpendicular from the origin to ℓ. It is transformed to the point
Rc + b = Rc + b⊥ + bk .
Since c ⊥ ℓ, its rotation Rc about an axis parallel to ℓ and through the origin must be perpendicular
to ℓ as well. The point Rc + b⊥ must be in the plane containing c and the perpendicular to ℓ.
Meanwhile, the same point must also lie on the axis ℓ in order for Rc + b, its sum with bk , to lie
on ℓ. We thus infer
c = Rc + b⊥ ,
from which we obtain
c = (I3 − R)−1 b⊥ ,
where the inverse (I3 − R)−1 exists due to the uniqueness of c. The moment m of ℓ is
l × c = (R − RT )c
= (R − RT )(I3 − R)−1 b⊥ . (17)
Since
(RT + I3 )(I3 − R) = RT + I3 − I3 − R
= RT − R,
we have
−(RT + I3 ) = (R − RT )(I3 − R)−1 .
Substitute the above into (17):
The screw axis is thus given the Plücker coordinates (l, m).
13
References
[1] J. Craig. Introduction to Robotics: Mechanics and Control. 2nd ed., Addison-Wesley, 1989.
[2] J. B. Kuipers. Quaternions and Rotation Sequences. Princeton University Press, 1999.
[4] http://sundaram.wordpress.com/2013/03/08/mathematical-reason-behind-gimbal-lock
-in-euler-angles/.
14