Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Euler Angle Formulas

David Eberly
Geometric Tools, LLC
http://www.geometrictools.com/
Copyright c 1998-2014. All Rights Reserved.
Created: December 1, 1999
Last Modied: March 10, 2014
Contents
1 Introduction 3
2 Factor as a Product of Three Rotation Matrices 3
2.1 Factor as R
x
R
y
R
z
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Factor as R
x
R
z
R
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Factor as R
y
R
x
R
z
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Factor as R
y
R
z
R
x
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5 Factor as R
z
R
x
R
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6 Factor as R
z
R
y
R
x
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.7 Factor as R
x0
R
y
R
x1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.8 Factor as R
x0
R
z
R
x1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.9 Factor as R
y0
R
x
R
y1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.10 Factor as R
y0
R
z
R
y1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.11 Factor as R
z0
R
x
R
z1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.12 Factor as R
z0
R
y
R
z1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 Factor as a Product of Two Rotation Matrices 19
3.1 Factor P
x
P
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Factor P
y
P
x
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.3 Factor P
x
P
z
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4 Factor P
z
P
x
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5 Factor P
y
P
z
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1
3.6 Factor P
z
P
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2
1 Introduction
Rotations about the coordinate axes are easy to dene and work with. Rotation about the x-axis by angle
is
R
x
() =

1 0 0
0 cos sin
0 sin cos

where > 0 indicates a counterclockwise rotation in the plane x = 0. The observer is assumed to be
positioned on the side of the plane with x > 0 and looking at the origin. Rotation about the y-axis by angle
is
R
y
() =

cos 0 sin
0 1 0
sin 0 cos

where > 0 indicates a counterclockwise rotation in the plane y = 0. The observer is assumed to be
positioned on the side of the plane with y > 0 and looking at the origin. Rotation about the z-axis by angle
is
R
z
() =

cos sin 0
sin cos 0
0 0 1

where > 0 indicates a counterclockwise rotation in the plane z = 0. The observer is assumed to be
positioned on the side of the plane with z > 0 and looking at the origin. Rotation by an angle about an
arbitrary axis containing the origin and having unit length direction U = (U
x
, U
y
, U
z
) is given by
R
U
() = I + (sin )S + (1 cos )S
2
where I is the identity matrix,
S =

0 U
z
U
y
U
z
0 U
x
U
y
U
x
0

and > 0 indicates a counterclockwise rotation in the plane U (x, y, z) = 0. The observer is assumed to be
positioned on the side of the plane to which U points and is looking at the origin.
2 Factor as a Product of Three Rotation Matrices
A common problem is to factor a rotation matrix as a product of rotations about the coordinate axes.
The form of the factorization depends on the needs of the application and what ordering is specied. For
example, one might want to factor a rotation as R = R
x
(
x
)R
y
(
y
)R
z
(
z
) for some angles
x
,
y
, and
z
.
The ordering is xyz. Five other possibilities are xzy, yxz, yzx, zxy, and zyx. It is also possible to factor
as R = R
x
(
x0
)R
y
(
y
)R
x
(
x1
), the ordering referred to as xyx. Five other possibilites are xzx, yxy, yzy,
zxz, and zyz. These are also discussed here. The following discussion uses the notation c
a
= cos(
a
) and
s
a
= sin(
a
) for a = x, y, z.
3
2.1 Factor as R
x
R
y
R
z
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
x
(
x
)R
y
(
y
)R
z
(
z
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
c
y
s
z
s
y
c
z
s
x
s
y
+ c
x
s
z
c
x
c
z
s
x
s
y
s
z
c
y
s
x
c
x
c
z
s
y
+ s
x
s
z
c
z
s
x
+ c
x
s
y
s
z
c
x
c
y

The simplest term to work with is s


y
= r
02
, so
y
= asin(r
02
). There are three cases to consider.
Case 1: If
y
(/2, /2), then c
y
= 0 and c
y
(s
x
, c
x
) = (r
12
, r
22
), in which case
x
= atan2(r
12
, r
22
),
and c
y
(s
z
, c
z
) = (r
01
, r
00
), in which case
z
= atan2(r
01
, r
00
). In summary,

y
= asin(r
02
),
x
= atan2(r
12
, r
22
).
z
= atan2(r
01
, r
00
) (1)
Case 2: If
y
= /2, then s
y
= 1 and c
y
= 0. In this case

r
10
r
11
r
20
r
21

c
z
s
x
+ c
x
s
z
c
x
c
z
s
x
s
z
c
x
c
z
+ s
x
s
z
c
z
s
x
+ c
x
s
z

sin(
z
+
x
) cos(
z
+
x
)
cos(
z
+
x
) sin(
z
+
x
)

.
Therefore,
z
+
x
= atan2(r
10
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= /2,
z
+
x
= atan2(r
10
, r
11
) (2)
Case 3: If
y
= /2, then s
y
= 1 and c
y
= 0. In this case

r
10
r
11
r
20
r
21

c
z
s
x
+ c
x
s
z
c
x
c
z
+ s
x
s
z
c
x
c
z
+ s
x
s
z
c
z
s
x
c
x
s
z

sin(
z

x
) cos(
z

x
)
cos(
z

x
) sin(
z

x
)

.
Therefore,
z

x
= atan2(r
10
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= /2,
z

x
= atan2(r
10
, r
11
) (3)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
02
is tested for the three cases.
if (r02 < +1)
{
if (r02 > -1)
{
thetaY = asin(r02);
thetaX = atan2(-r12,r22);
thetaZ = atan2(-r01,r00);
}
else // r02 = -1
4
{
// Not a unique solution: thetaZ - thetaX = atan2(r10,r11)
thetaY = -PI/2;
thetaX = -atan2(r10,r11);
thetaZ = 0;
}
}
else // r02 = +1
{
// Not a unique solution: thetaZ + thetaX = atan2(r10,r11)
thetaY = +PI/2;
thetaX = atan2(r10,r11);
thetaZ = 0;
}
2.2 Factor as R
x
R
z
R
y
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
x
(
x
)R
z
(
z
)R
y
(
y
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
s
z
c
z
s
y
s
x
s
y
+ c
x
c
y
s
z
c
x
c
z
c
y
s
x
+ c
x
s
y
s
z
c
x
s
y
+ c
y
s
x
s
z
c
z
s
x
c
x
c
y
+ s
x
s
y
s
z

The simplest term to work with is s


z
= r
01
, so
z
= asin(r
01
). There are three cases to consider.
Case 1: If
z
(/2, /2), then c
z
= 0 and c
z
(s
y
, c
y
) = (r
02
, r
00
), in which case
y
= atan2(r
02
, r
00
), and
c
z
(s
x
, c
x
) = (r
21
, r
11
), in which case
x
= atan2(r
21
, r
11
). In summary,

z
= asin(r
01
),
x
= atan2(r
21
, r
11
),
y
= atan2(r
02
, r
00
) (4)
Case 2: If
z
= /2, then s
z
= 1 and c
z
= 0. In this case

r
10
r
12
r
20
r
22

s
x
s
y
+ c
x
c
y
c
y
s
x
+ c
x
s
y
c
x
s
y
+ c
y
s
x
c
x
c
y
+ s
x
s
y

cos(
y

x
) sin(
y

x
)
sin(
y

x
) cos(
y

x
)

Therefore,
y

x
= atan2(r
20
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= +/2,
y

x
= atan2(r
20
, r
22
) (5)
Case 3: If
z
= /2, then s
z
= 1 and c
z
= 0. In this case

r
10
r
12
r
20
r
22

s
x
s
y
c
x
c
y
c
y
s
x
c
x
s
y
c
x
s
y
c
y
s
x
c
x
c
y
s
x
s
y

cos(
y
+
x
) sin(
y
+
x
)
sin(
y
+
x
) cos(
y
+
x
)

Therefore,
y
+
x
= atan2(r
20
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= /2,
y
+
x
= atan2(r
20
, r
22
) (6)
5
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
01
is tested for the three cases.
if (r01 < +1)
{
if (r01 > -1)
{
thetaZ = asin(-r01);
thetaX = atan2(r21,r11);
thetaY = atan2(r02,r00);
}
else // r01 = -1
{
// Not a unique solution: thetaY - thetaX = atan2(-r20,r22)
theta_z = +pi/2;
theta_x = -atan2(-r20,r22);
theta_y = 0;
}
}
else // r01 = +1
{
// Not a unique solution: thetaY + thetaX = atan2(-r20,r22)
theta_z = -pi/2;
theta_x = atan2(-r20,r22);
theta_y = 0;
}
2.3 Factor as R
y
R
x
R
z
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
y
(
y
)R
x
(
x
)R
z
(
z
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
+ s
x
s
y
s
z
c
z
s
x
s
y
c
y
s
z
c
x
s
y
c
x
s
z
c
x
c
z
s
x
c
z
s
y
+ c
y
s
x
s
z
c
y
c
z
s
x
+ s
y
s
z
c
x
c
y

The simplest term to work with is s


x
= r
12
, so
x
= asin(r
12
). There are three cases to consider.
Case 1: If
x
(/2, /2), then c
x
= 0 and c
x
(s
y
, c
y
) = (r
02
, r
22
), in which case
y
= atan2(r
02
, r
22
), and
c
x
(s
z
, c
z
) = (r
10
, r
11
), in which case
z
= atan2(r
10
, r
11
). In summary,

x
= asin(r
12
),
y
= atan2(r
02
, r
22
),
z
= atan2(r
10
, r
11
) (7)
Case 2: If
x
= /2, then s
x
= 1 and c
x
= 0. In this case,

r
00
r
01
r
20
r
21

c
y
c
z
+ s
y
s
z
c
z
s
y
c
y
s
z
c
z
s
y
+ c
y
s
z
c
y
c
z
+ s
y
s
z

cos(
z

y
) sin(
z

y
)
sin(
z

y
) cos(
z

y
)

6
Therefore,
z

y
= atan2(r
01
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= +/2,
z

y
= atan2(r
01
, r
00
) (8)
Case 3: If
x
= /2, then s
x
= 1 and c
x
= 0. In this case,

r
00
r
01
r
20
r
21

c
y
c
z
s
y
s
z
c
z
s
y
c
y
s
z
c
z
s
y
c
y
s
z
c
y
c
z
+ s
y
s
z

cos(
z
+
y
) sin(
z
+
y
)
sin(
z
+
y
) cos(
z
+
y
)

Therefore,
z
+
y
= atan2(r
01
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= /2,
z
+
y
= atan2(r
01
, r
00
) (9)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
12
is tested for the three cases.
if (r12 < +1)
{
if (r12 > -1)
{
thetaX = asin(-r12);
thetaY = atan2(r02,r22);
thetaZ = atan2(r10,r11);
}
else // r12 = -1
{
// Not a unique solution: thetaZ - thetaY = atan2(-r01,r00)
thetaX = +pi/2;
thetaY = -atan2(-r01,r00);
thetaZ = 0;
}
}
else // r12 = +1
{
// Not a unique solution: thetaZ + thetaY = atan2(-r01,r00)
thetaX = -pi/2;
thetaY = atan2(-r01,r00);
thetaZ = 0;
}
2.4 Factor as R
y
R
z
R
x
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
y
(
y
)R
z
(
z
)R
x
(
x
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
s
x
s
y
c
x
c
y
s
z
c
x
s
y
+ c
y
s
x
s
z
s
z
c
x
c
z
c
z
s
x
c
z
s
y
c
y
s
x
+ c
x
s
y
s
z
c
x
c
y
s
x
s
y
s
z

7
The simplest term to work with is s
z
= r
10
, so
z
= asin(r
10
). There are three cases to consider.
Case 1: If
z
(/2, /2), then c
z
= 0 and c
z
(s
x
, c
x
) = (r
12
, r
11
), in which case
x
= atan2(r
12
, r
11
),
and c
z
(s
y
, c
y
) = (r
20
, r
00
), in which case
y
= atan2(r
20
, r
00
). In summary,

z
= asin(r
10
),
y
= atan2(r
20
, r
00
),
x
= atan2(r
12
, r
11
) (10)
Case 2: If
z
= /2, then s
z
= 1 and c
z
= 0. In this case,

r
01
r
02
r
21
r
22

s
x
s
y
c
x
c
y
c
x
s
y
+ c
y
s
x
c
y
s
x
+ c
x
s
y
c
x
c
y
s
x
s
y

cos(
x
+
y
) sin(
x
+
y
)
sin(
x
+
y
) cos(
x
+
y
)

Therefore,
x
+
y
= atan2(r
21
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= +/2,
x
+
y
= atan2(r
21
, r
22
) (11)
Case 3: If
z
= /2, then s
z
= 1 and c
z
= 0. In this case,

r
01
r
02
r
21
r
22

s
x
s
y
+ c
x
c
y
c
x
s
y
c
y
s
x
c
y
s
x
c
x
s
y
c
x
c
y
+ s
x
s
y

cos(
x

y
) sin(
x

y
)
sin(
x

y
) cos(
x

y
)

Therefore,
x

y
= atan2(r
21
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= /2,
x

y
= atan2(r
21
, r
22
) (12)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
10
is tested for the three cases.
if (r10 < +1)
{
if (r10 > -1)
{
thetaZ = asin(r10);
thetaY = atan2(-r20,r00);
thetaX = atan2(-r12,r11);
}
else // r10 = -1
{
// Not a unique solution: thetaX - thetaY = atan2(r21,r22)
thetaZ = -pi/2;
thetaY = -atan2(r21,r22);
thetaX = 0;
}
}
else
{
// Not a unique solution: thetaX + thetaY = atan2(r21,r22)
8
thetaZ = +pi/2;
thetaY = atan2(r21,r22);
thetaX = 0;
}
2.5 Factor as R
z
R
x
R
y
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
z
(
z
)R
x
(
x
)R
y
(
y
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
s
x
s
y
s
z
c
x
s
z
c
z
s
y
+ c
y
s
x
s
z
c
z
s
x
s
y
+ c
y
s
z
c
x
c
z
c
y
c
z
s
x
+ s
y
s
z
c
x
s
y
s
x
c
x
c
y

The simplest term to work with is s


x
= r
21
, so
x
= asin(r
21
). There are three cases to consider.
Case 1: If
x
(/2, /2), then c
x
= 0 and c
x
(s
y
, c
y
) = (r
20
, r
22
), in which case
y
= atan2(r
20
, r
22
),
and c
x
(s
z
, c
z
) = (r
01
, r
11
), in which case
z
= atan2(r
01
, r
11
). In summary,

x
= asin(r
21
),
z
= atan2(r
01
, r
11
),
y
= atan2(r
20
, r
22
) (13)
Case 2: If
x
= /2, then s
x
= 1 and c
z
= 0. In this case,

r
00
r
02
r
10
r
12

c
y
s
z
s
y
c
z
c
z
s
y
+ c
y
s
z
c
z
s
y
+ c
y
s
z
c
y
c
z
+ s
y
s
z

cos(
y
+
z
) sin(
y
+
z
)
sin(
y
+
z
) cos(
y
+
z
)

Therefore,
y
+
z
= atan2(r
02
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= +/2,
y
+
z
= atan2(r
02
, r
00
) (14)
Case 3: If
x
= /2, then s
x
= 1 and c
x
= 0. In this case,

r
00
r
02
r
10
r
12

c
y
s
z
+ s
y
c
z
c
z
s
y
c
y
s
z
c
z
s
y
+ c
y
s
z
c
y
c
z
+ s
y
s
z

cos(
y

z
) sin(
y

z
)
sin(
y

z
) cos(
y

z
)

Therefore,
y

z
= atan2(r
02
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= /2,
y

z
= atan2(r
02
, r
00
) (15)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
21
is tested for the three cases.
if (r21 < +1)
{
if (r21 > -1)
{
9
thetaX = asin(r21);
thetaZ = atan2(-r01,r11);
thetaY = atan2(-r20,r22);
}
else // r21 = -1
{
// Not a unique solution: thetaY - thetaZ = atan2(r02,r00)
thetaX = -pi/2;
thetaZ = -atan2(r02,r00);
thetaY = 0;
}
}
else // r21 = +1
{
// Not a unique solution: thetaY + thetaZ = atan2(r02,r00)
thetaX = +pi/2;
thetaZ = atan2(r02,r00);
thetaY = 0;
}
2.6 Factor as R
z
R
y
R
x
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
z
(
z
)R
y
(
y
)R
x
(
x
), and equating yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z
c
z
s
x
s
y
c
x
s
z
c
x
c
z
s
y
+ s
x
s
z
c
y
s
z
c
x
c
z
+ s
x
s
y
s
z
c
z
s
x
+ c
x
s
y
s
z
s
y
c
y
s
x
c
x
c
y

The simplest term to work with is s


y
= r
20
, so
y
= asin(r
20
). There are three cases to consider.
Case 1: If
y
(/2, /2), then c
y
= 0 and c
y
(s
x
, c
x
) = (r
21
, r
22
), in which case
x
= atan2(r
21
, r
22
), and
c
y
(s
z
, c
z
) = (r
10
, r
00
), in which case
z
= atan2(r
10
, r
00
). In summary,

y
= asin(r
20
),
z
= atan2(r
10
, r
00
),
x
= atan2(r
21
, r
22
) (16)
Case 2: If
y
= /2, then s
y
= 1 and c
y
= 0. In this case,

r
01
r
02
r
11
r
12

c
z
s
x
c
x
s
z
c
x
c
z
+ s
x
s
z
c
x
c
z
+ s
x
s
z
c
z
s
x
+ c
x
s
z

sin(
x

z
) cos(
x

z
)
cos(
x

z
) sin(
x

z
)

Therefore,
x

z
= atan2(r
12
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= +/2,
x

z
= atan2(r
12
, r
11
) (17)
10
Case 3: If
y
= /2, then s
y
= 1 and c
y
= 0. In this case,

r
01
r
02
r
11
r
12

c
z
s
x
c
x
s
z
c
x
c
z
+ s
x
s
z
c
x
c
z
s
x
s
z
c
z
s
x
c
x
s
z

sin(
x
+
z
) cos(
x
+
z
)
cos(
x
+
z
) sin(
x
+
z
)

Therefore,
x
+
z
= atan2(r
12
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= /2,
x
+
z
= atan2(r
12
, r
11
) (18)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
20
is tested for the three cases.
if (r20 < +1)
{
if (r20 > -1)
{
thetaY = asin(-r20);
thetaZ = atan2(r10,r00);
thetaX = atan2(r21,r22);
}
else // r20 = -1
{
// Not a unique solution: thetaX - thetaZ = atan2(-r12,r11)
thetaY = +pi/2;
thetaZ = -atan2(-r12,r11);
thetaX = 0;
}
}
else // r20 = +1
{
// Not a unique solution: thetaX + thetaZ = atan2(-r12,r11)
thetaY = -pi/2;
thetaZ = atan2(-r12,r11);
thetaX = 0;
}
2.7 Factor as R
x
0
R
y
R
x
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
x
(
x0
)R
y
(
y
)R
x
(
x1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
s
y
s
x1
s
y
c
x1
s
y
s
x0
c
x0
c
x1
c
y
s
x0
s
x1
c
y
c
x1
s
x0
c
x0
s
x1
s
y
c
x0
c
x1
s
x0
+ c
y
c
x0
s
x1
c
y
c
x0
c
x1
s
x0
s
x1

The simplest term to work with is c


y
= r
00
, so
y
= acos(r
00
). There are three cases to consider.
11
Case 1: If
y
(0, ), then s
y
= 0 and s
y
(s
x0
, c
x0
) = (r
10
, r
20
), in which case
x0
= atan2(r
10
, r
20
), and
s
y
(s
x1
, c
x1
) = (r
01
, r
02
), in which case
x1
= atan2(r
01
, r
02
). In summary,

y
= acos(r
00
),
x0
= atan2(r
10
, r
20
),
x1
= atan2(r
01
, r
02
) (19)
Case 2: If
y
= 0, then c
y
= 1 and s
y
= 0. In this case,

r
11
r
12
r
21
r
22

c
x0
c
x1
s
x0
s
x1
c
x1
s
x0
c
x0
s
x1
c
x1
s
x0
+ c
x0
s
x1
c
x0
c
x1
s
x0
s
x1

cos(
x1
+
x0
) sin(
x1
+
x0
)
sin(
x1
+
x0
) cos(
x1
+
x0
)

Therefore,
x1
+
x0
= atan2(r
12
, r
11
). There is one degree of freedom, so the factorization is not unique.
In summary,

y
= 0,
x1
+
x0
= atan2(r
12
, r
11
) (20)
Case 3: If
y
= , then c
y
= 1 and s
y
= 0. In this case,

r
11
r
12
r
21
r
22

c
x0
c
x1
+ s
x0
s
x1
c
x1
s
x0
c
x0
s
x1
c
x1
s
x0
c
x0
s
x1
c
x0
c
x1
s
x0
s
x1

cos(
x1

x0
) sin(
x1

x0
)
sin(
x1

x0
) cos(
x1

x0
)

Therefore,
x1

x0
= atan2(r
12
, r
11
). There is one degree of freedom, so the factorization is not unique.
In summary,

y
= ,
x1

x0
= atan2(r
12
, r
11
) (21)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
00
is tested for the three cases.
if (r00 < +1)
{
if (r00 > -1)
{
thetaY = acos(r00);
thetaX0 = atan2(r10,-r20);
thetaX1 = atan2(r01,r02);
}
else // r00 = -1
{
// Not a unique solution: thetaX1 - thetaX0 = atan2(-r12,r11)
thetaY = pi;
thetaX0 = -atan2(-r12,r11);
thetaX1 = 0;
}
}
else // r00 = +1
{
// Not a unique solution: thetaX1 + thetaX0 = atan2(-r12,r11)
thetaY = 0;
thetaX0 = atan2(-r12,r11);
thetaX1 = 0;
}
12
2.8 Factor as R
x
0
R
z
R
x
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
x
(
x0
)R
y
(
y
)R
z
(
x1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
z
s
z
c
x1
s
z
s
x1
s
z
c
x0
c
z
c
x0
c
x1
s
x0
s
x1
c
x1
s
x0
c
z
c
x0
s
x1
s
z
s
x0
c
z
c
x1
s
x0
+ c
x0
s
x1
c
x0
c
x1
c
z
s
x0
s
x1

The simplest term to work with is c


z
= r
00
, so
z
= acos(r
00
). There are three cases to consider.
Case 1: If
z
(0, ), then s
z
= 0 and s
z
(s
x0
, c
x0
) = (r
20
, r
10
), in which case
x0
= atan2(r
20
, r
10
), and
s
z
(s
x1
, c
x1
) = (r
02
, r
01
), in which case
x1
= atan2(r
02
, r
01
). In summary,

z
= acos(r
00
),
x0
= atan2(r
20
, r
10
),
x1
= atan2(r
02
, r
01
) (22)
Case 2: If
z
= 0, then c
z
= 1 and s
z
= 0. In this case,

r
11
r
12
r
21
r
22

c
x0
c
x1
s
x0
s
x1
c
x1
s
x0
c
x0
s
x1
c
x1
s
x0
+ c
x0
s
x1
c
x0
c
x1
s
x0
s
x1

cos(
x1
+
x0
) sin(
x1
+
x0
)
sin(
x1
+
x0
) cos(
x1
+
x0
)

Therefore,
x1
+
x0
= atan2(r
21
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= 0,
x1
+
x0
= atan2(r
21
, r
22
) (23)
Case 3: If
z
= , then c
z
= 1 and s
z
= 0. In this case,

r
11
r
12
r
21
r
22

c
x0
c
x1
s
x0
s
x1
c
x1
s
x0
+ c
x0
s
x1
c
x1
s
x0
+ c
x0
s
x1
c
x0
c
x1
+ s
x0
s
x1

cos(
x1

x0
) sin(
x1

x0
)
sin(
x1

x0
) cos(
x1

x0
)

Therefore,
x1

x0
= atan2(r
21
, r
22
). There is one degree of freedom, so the factorization is not unique. In
summary,

z
= ,
x1

x0
= atan2(r
21
, r
22
) (24)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
00
is tested for the three cases.
if (r00 < +1)
{
if (r00 > -1)
{
thetaZ = acos(r00);
thetaX0 = atan2(r20,r10);
thetaX1 = atan2(r02,-r01);
}
else // r00 = -1
{
13
// Not a unique solution: thetaX1 - thetaX0 = atan2(r21,r22)
thetaZ = pi;
thetaX0 = -atan2(r21,r22);
thetaX1 = 0;
}
}
else // r00 = +1
{
// Not a unique solution: thetaX1 + thetaX0 = atan2(r21,r22)
thetaZ = 0;
thetaX0 = atan2(r21,r22);
thetaX1 = 0;
}
2.9 Factor as R
y
0
R
x
R
y
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
y
(
y0
)R
x
(
x
)R
y
(
y1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y0
c
y1
c
x
s
y0
s
y1
s
x
s
y0
c
x
c
y1
s
y0
+ c
y0
s
y1
s
x
s
y1
c
x
s
x
c
y1
c
y1
s
y0
c
x
c
y0
s
y1
s
x
c
y0
c
x
c
y0
c
y1
s
y0
s
y1

The simplest term to work with is c


x
= r
11
, so
x
= acos(r
11
). There are three cases to consider.
Case 1: If
x
(0, ), then s
x
= 0 and s
x
(s
y0
, c
y0
) = (r
01
, r
21
), in which case
y0
= atan2(r
01
, r
21
), and
s
x
(s
y1
, c
y1
) = (r
10
, r
12
), in which case
y1
= atan2(r
10
, r
12
). In summary,

x
= acos(r
11
),
y0
= atan2(r
01
, r
21
),
y1
= atan2(r
10
, r
12
) (25)
Case 2: If
x
= 0, then c
x
= 1 and s
x
= 0. In this case,

r
00
r
02
r
20
r
22

c
y0
c
y1
s
y0
s
y1
c
y1
s
y0
+ c
y0
s
y1
c
y1
s
y0
c
y0
s
y1
c
y0
c
y1
s
y0
s
y1

cos(
y1
+
y0
) sin(
y1
+
y0
)
sin(
y1
+
y0
) cos(
y1
+
y0
)

Therefore,
y1
+
y0
= atan2(r
02
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= 0,
y1
+
y0
= atan2(r
02
, r
00
) (26)
Case 3: If
x
= , then c
x
= 1 and s
x
= 0. In this case,

r
00
r
02
r
20
r
22

c
y0
c
y1
+ s
y0
s
y1
c
y1
s
y0
+ c
y0
s
y1
c
y1
s
y0
+ c
y0
s
y1
c
y0
c
y1
s
y0
s
y1

cos(
y1

y0
) sin(
y1

y0
)
sin(
y1

y0
) cos(
y1

y0
)

Therefore,
y1

y0
= atan2(r
02
, r
00
). There is one degree of freedom, so the factorization is not unique. In
summary,

x
= ,
y1

y0
= atan2(r
02
, r
00
) (27)
14
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
11
is tested for the three cases.
if (r11 < +1)
{
if (r11 > -1)
{
thetaX = acos(r11);
thetaY0 = atan2(r01,r21);
thetaY1 = atan2(r10,-r12);
}
else // r11 = -1
{
// Not a unique solution: thetaY1 - thetaY0 = atan2(r02,r00)
thetaX = pi;
thetaY0 = -atan2(r02,r00);
thetaY1 = 0;
}
}
else // r11 = +1
{
// Not a unique solution: thetaY1 + thetaY0 = atan2(r02,r00)
thetaX = 0;
thetaY0 = atan2(r02,r00);
thetaY1 = 0;
}
2.10 Factor as R
y
0
R
z
R
y
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
y
(
y0
)R
z
(
z
)R
y
(
y1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
z
c
y0
c
y1
s
y0
s
y1
s
z
c
y0
c
y1
s
y0
+ c
z
c
y0
s
y1
s
z
c
y1
c
z
s
z
s
y1
c
z
c
y1
s
y0
c
y0
s
y1
s
z
s
y0
c
y0
c
y1
c
z
s
y0
s
y1

The simplest term to work with is c


z
= r
11
, so
z
= acos(r
11
). There are three cases to consider.
Case 1: If
z
(0, ), then s
z
= 0 and s
z
(s
y0
, c
y0
) = (r
21
, r
01
), in which case
y0
= atan2(r
21
, r
01
), and
s
z
(s
y1
, c
y1
) = (r
12
, r
10
), in which case
y1
= atan2(r
12
, r
10
). In summary,

z
= acos(r
11
),
y0
= atan2(r
21
, r
01
),
y1
= atan2(r
12
, r
10
) (28)
Case 2: If
z
= 0, then c
z
= 1 and s
z
= 0. In this case,

r
00
r
02
r
20
r
22

c
y0
c
y1
s
y0
s
y1
c
y1
s
y0
+ c
y0
s
y1
c
y1
s
y0
c
y0
s
y1
c
y0
c
y1
s
y0
s
y1

cos(
y1
+
y0
) sin(
y1
+
y0
)
sin(
y1
+
y0
) cos(
y1
+
y0
)

15
Therefore,
y1
+
y0
= atan2(r
20
, r
22
). There is one degree of freedom, so the factorization is not unique.
In summary,

z
= 0,
y1
+
y0
= atan2(r
20
, r
22
) (29)
Case 3: If
z
= , then c
z
= 1 and s
z
= 0. In this case,

r
00
r
02
r
20
r
22

c
y0
c
y1
s
y0
s
y1
c
y1
s
y0
c
y0
s
y1
c
y1
s
y0
c
y0
s
y1
c
y0
c
y1
+ s
y0
s
y1

cos(
y1

y0
) sin(
y1

y0
)
sin(
y1

y0
) cos(
y1

y0
)

Therefore,
y1

y0
= atan2(r
20
, r
22
). There is one degree of freedom, so the factorization is not unique.
In summary,

z
= ,
y1

y0
= atan2(r
20
, r
22
) (30)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
11
is tested for the three cases.
if (r11 < +1)
{
if (r11 > -1)
{
thetaZ = acos(r11);
thetaY0 = atan2(r21,-r01);
thetaY1 = atan2(r12,r10);
}
else // r11 = -1
{
// Not a unique solution: thetaY1 - thetaY0 = atan2(-r20,r22)
thetaZ = pi;
thetaY0 = -atan2(-r20,r22);
thetaY1 = 0;
}
}
else // r11 = +1
{
// Not a unique solution: thetaY1 + thetaY0 = atan2(-r20,r22)
thetaZ = 0;
thetaY0 = atan2(-r20,r22);
thetaY1 = 0;
}
16
2.11 Factor as R
z
0
R
x
R
z
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
z
(
z0
)R
x
(
x
)R
z
(
z1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
z0
c
z1
c
x
s
z0
s
z1
c
x
c
z1
s
z0
c
z0
s
z1
s
x
s
z0
c
z1
s
z0
+ c
x
c
z0
s
z1
c
x
c
z0
c
z1
s
z0
s
z1
s
x
c
z0
s
x
s
z1
s
x
c
z1
c
x

The simplest term to work with is c


x
= r
22
, so
x
= acos(r
22
). There are three cases to consider.
Case 1: If
x
(0, ), then s
x
= 0 and s
x
(s
z0
, c
z0
) = (r
02
, r
12
), in which case
z0
= atan2(r
02
, r
12
), and
s
x
(s
z1
, c
z1
) = (r
20
, r
21
), in which case
z1
= atan2(r
20
, r
21
). In summary,

x
= acos(r
22
),
z0
= atan2(r
02
, r
12
),
z1
= atan2(r
20
, r
21
) (31)
Case 2: If
x
= 0, then c
x
= 1 and s
x
= 0. In this case,

r
00
r
01
r
10
r
11

c
z0
c
z1
s
z0
s
z1
c
z1
s
z0
c
z0
s
z1
c
z1
s
z0
+ c
z0
s
z1
c
z0
c
z1
s
z0
s
z1

cos(
z1
+
z0
) sin(
z1
+
z0
)
sin(
z1
+
z0
) cos(
z1
+
z0
)

Therefore,
z1
+
z0
= atan2(r
01
, r
00
). There is one degree of freedom, so the factorization is not unique.
In summary,

x
= 0,
z1
+
z0
= atan2(r
01
, r
00
) (32)
Case 3: If
x
= , then c
x
= 1 and s
x
= 0. In this case,

r
00
r
01
r
10
r
11

c
z0
c
z1
+ s
z0
s
z1
c
z1
s
z0
c
z0
s
z1
c
z1
s
z0
c
z0
s
z1
c
z0
c
z1
s
z0
s
z1

cos(
z1

z0
) sin(
z1

z0
)
sin(
z1

z0
) cos(
z1

z0
)

Therefore,
z1

z0
= atan2(r
01
, r
00
). There is one degree of freedom, so the factorization is not unique.
In summary,

x
= ,
z1

z0
= atan2(r
01
, r
00
) (33)
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
22
is tested for the three cases.
if (r22 < +1)
{
if (r22 > -1)
{
thetaX = acos(r22);
thetaZ0 = atan2(r02,-r12);
thetaZ1 = atan2(r20,r21);
}
else // r22 = -1
{
17
// Not a unique solution: thetaZ1 - thetaZ0 = atan2(-r01,r00)
thetaX = pi;
thetaZ0 = -atan2(-r01,r00);
thetaZ1 = 0;
}
}
else // r22 = +1
{
// Not a unique solution: thetaZ1 + thetaZ0 = atan2(-r01,r00)
thetaX = 0;
thetaZ0 = atan2(-r01,r00);
thetaZ1 = 0;
}
2.12 Factor as R
z
0
R
y
R
z
1
Setting R = [r
ij
] for 0 i 2 and 0 j 2, formally multiplying R
z
(
z0
)R
y
(
y
)R
z
(
z1
), and equating
yields

r
00
r
01
r
02
r
10
r
11
r
12
r
20
r
21
r
22

c
y
c
z0
c
z1
s
z0
s
z1
c
z1
s
z0
c
y
c
z0
s
z1
s
y
c
z0
c
y
c
z1
s
z0
+ c
z0
s
z1
c
z0
c
z1
c
y
s
z0
s
z1
s
y
s
z0
s
y
c
z1
s
y
s
z1
c
y

The simplest term to work with is c


y
= r
22
, so
y
= acos(r
22
). There are three cases to consider.
Case 1: If
y
(0, ), then s
y
= 0 and s
y
(s
z0
, c
z0
) = (r
12
, r
02
), in which case
z0
= atan2(r
12
, r
02
), and
s
y
(s
z1
, c
z1
) = (r
21
, r
20
), in which case
z1
= atan2(r
20
, r
21
). In summary,

y
= acos(r
22
),
z0
= atan2(r
12
, r
02
),
z1
= atan2(r
21
, r
20
) (34)
Case 2: If
y
= 0, then c
y
= 1 and s
y
= 0. In this case,

r
00
r
01
r
10
r
11

c
z0
c
z1
s
z0
s
z1
c
z1
s
z0
c
z0
s
z1
c
z1
s
z0
+ c
z0
s
z1
c
z0
c
z1
s
z0
s
z1

cos(
z1
+
z0
) sin(
z1
+
z0
)
sin(
z1
+
z0
) cos(
z1
+
z0
)

Therefore,
z1
+
z0
= atan2(r
10
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= 0,
z1
+
z0
= atan2(r
10
, r
11
) (35)
Case 3: If
y
= , then c
y
= 1 and s
y
= 0. In this case,

r
00
r
01
r
10
r
11

c
z0
c
z1
s
z0
s
z1
c
z1
s
z0
+ c
z0
s
z1
c
z1
s
z0
+ c
z0
s
z1
c
z0
c
z1
+ s
z0
s
z1

cos(
z1
+
z0
) sin(
z1
+
z0
)
sin(
z1
+
z0
) cos(
z1
+
z0
)

Therefore,
z1

z0
= atan2(r
10
, r
11
). There is one degree of freedom, so the factorization is not unique. In
summary,

y
= ,
z1

z0
= atan2(r
10
, r
11
) (36)
18
Pseudocode for the factorization is listed below. To avoid the arcsin call until needed, the matrix entry r
22
is tested for the three cases.
if (r22 < +1)
{
if (r22 > -1)
{
thetaY = acos(r22);
thetaZ0 = atan2(r12,r02);
thetaZ1 = atan2(r21,-r20);
}
else // r22 = -1
{
// Not a unique solution: thetaZ1 - thetaZ0 = atan2(r10,r11)
thetaY = pi;
thetaZ0 = -atan2(r10,r11);
thetaZ1 = 0;
}
}
else // r22 = +1
{
// Not a unique solution: thetaZ1 + thetaZ0 = atan2(r10,r11)
thetaY = 0;
thetaZ0 = atan2(r10,r11);
thetaZ1 = 0;
}
3 Factor as a Product of Two Rotation Matrices
Given a rotation R that is a product of two coordinate axis rotations, the problem is to factor it into
three coordinate axis rotations using the ordering xyz. Derivations for the other orderings are similar. In
the subsections the matrices are P
x
= R
x
(
x
), P
y
= R
y
(
y
), and P
z
= R
z
(
z
). Dene s
a
= sin(
x
),
s
b
= sin(
y
), s
c
= sin(
z
), c
a
= cos(
x
), c
b
= cos(
y
), and c
c
= cos(
z
).
3.1 Factor P
x
P
y
This is a trivial case. The factorization is R = R
x
(
x
)R
y
(
y
) = R
x
(
x
)R
y
(
y
)R
z
(
z
). Therefore,
x
=
x
,

y
=
y
, and
z
= 0.
19
3.2 Factor P
y
P
x
The factorization is R = R
y
(
y
)R
x
(
x
) = R
x
(
x
)R
y
(
y
)R
z
(
z
). Formal multiplication of the various terms
leads to the equation

c
b
s
a
s
b
c
a
s
b
0 c
a
s
a
s
b
c
b
s
a
c
a
c
b

c
y
c
z
c
y
s
z
s
y
c
z
s
x
s
y
+ c
x
s
z
c
x
c
z
s
x
s
y
s
z
c
y
s
x
c
x
c
z
s
y
+ s
x
s
z
c
z
s
x
+ c
x
s
y
s
z
c
x
c
y

.
It is easy to see that s
y
= c
a
s
b
in which case
y
= asin(cos
y
sin
x
). Adding the 10 and 21 terms yields
0 + c
b
s
a
= (c
z
s
x
s
y
+ c
x
s
z
) + (c
z
s
x
+ c
x
s
y
s
z
) = (1 + s
y
)(c
z
s
x
+ c
x
s
z
)
which leads to sin(
x
+
z
) = c
b
s
a
/(1 + c
a
s
b
). In the even that c
a
s
b
= 1, this leads to a special case in the
coding that is easy to solve. Subtracting the 10 term from the 21 term yields
c
b
s
a
0 = (c
z
s
x
s
y
+ c
x
s
z
) (c
z
s
x
+ c
x
s
y
s
z
) = (1 s
y
)(c
z
s
x
c
x
s
z
)
which leads to sin(
x

z
) = c
b
s
a
/(1 c
a
s
b
). In the event that c
a
s
b
= 1, this also leads to a special case in
the coding that is easy to solve. The sine functions can be inverted and the two resulting equations for
x
and
z
can be solved. For the case |c
a
s
b
| < 1,

x
=
1
2

asin

c
b
sa
1+c
b
sa

+ asin

c
b
sa
1c
b
sa

y
= asin(c
a
s
b
)

z
=
1
2

asin

c
b
sa
1+c
b
sa

asin

c
b
sa
1c
b
sa

3.3 Factor P
x
P
z
This is a trivial case. The factorization is R = R
x
(
x
)R
z
(
z
) = R
x
(
x
)R
y
(
y
)R
z
(
z
). Therefore,
x
=
x
,

y
= 0, and
z
=
z
.
3.4 Factor P
z
P
x
A construction similar to the case P
y
P
x
leads to

x
=
1
2

asin

cacc
1+sasc

+ asin

cacc
1sasc

y
= asin(s
a
s
c
)

z
=
1
2

asin

cacc
1+sasc

asin

cacc
1sasc

3.5 Factor P
y
P
z
This is a trivial case. The factorization is R = R
y
(
y
)R
z
(
z
) = R
x
(
x
)R
y
(
y
)R
z
(
z
). Therefore,
x
= 0,

y
=
y
, and
z
=
z
.
20
3.6 Factor P
z
P
y
A construction similar to the case P
y
P
x
leads to

x
=
1
2

asin

c
b
sc
1+s
b
cc

asin

c
b
sc
1s
b
cc

y
= asin(s
b
c
c
)

z
=
1
2

asin

c
b
sc
1+s
b
cc

+ asin

c
b
sc
1s
b
cc

21

You might also like