Spatial rotations in three dimensions can be parametrized using both Euler angles and unit quaternions . This article explains how to convert between the two representations. Actually this simple use of "quaternions" was first presented by Euler some seventy years earlier than Hamilton to solve the problem of magic squares . For this reason the dynamics community commonly refers to quaternions in this application as "Euler parameters".
Definition
A unit quaternion can be described as:
q
=
[
q
0
q
1
q
2
q
3
]
T
{\displaystyle \mathbf {q} ={\begin{bmatrix}q_{0}&q_{1}&q_{2}&q_{3}\end{bmatrix}}^{T}}
|
q
|
2
=
q
0
2
+
q
1
2
+
q
2
2
+
q
3
2
=
1
{\displaystyle |\mathbf {q} |^{2}=q_{0}^{2}+q_{1}^{2}+q_{2}^{2}+q_{3}^{2}=1}
We can associate a quaternion to a rotation around an axis by the following expression
q
0
=
cos
(
α
/
2
)
{\displaystyle \mathbf {q} _{0}=\cos(\alpha /2)}
q
1
=
sin
(
α
/
2
)
cos
(
β
x
)
{\displaystyle \mathbf {q} _{1}=\sin(\alpha /2)\cos(\beta _{x})}
q
2
=
sin
(
α
/
2
)
cos
(
β
y
)
{\displaystyle \mathbf {q} _{2}=\sin(\alpha /2)\cos(\beta _{y})}
q
3
=
sin
(
α
/
2
)
cos
(
β
z
)
{\displaystyle \mathbf {q} _{3}=\sin(\alpha /2)\cos(\beta _{z})}
where α is a simple rotation angle (the value in radians of the angle of rotation) and cos(βx ), cos(βy ) and cos(βz ) are the "direction cosines " locating the axis of rotation (Euler's Theorem).
Rotation matrices
Euler angles - The xyz (fixed) system is shown in blue, the XYZ (rotated) system is shown in red. The line of nodes, labelled N, is shown in green.
The orthogonal matrix corresponding to a rotation by the unit quaternion q is given by[clarification needed ]
[
1
−
2
(
q
2
2
+
q
3
2
)
2
(
q
1
q
2
−
q
0
q
3
)
2
(
q
0
q
2
+
q
1
q
3
)
2
(
q
1
q
2
+
q
0
q
3
)
1
−
2
(
q
1
2
+
q
3
2
)
2
(
q
2
q
3
−
q
0
q
1
)
2
(
q
1
q
3
−
q
0
q
2
)
2
(
q
0
q
1
+
q
2
q
3
)
1
−
2
(
q
1
2
+
q
2
2
)
]
{\displaystyle {\begin{bmatrix}1-2(q_{2}^{2}+q_{3}^{2})&2(q_{1}q_{2}-q_{0}q_{3})&2(q_{0}q_{2}+q_{1}q_{3})\\2(q_{1}q_{2}+q_{0}q_{3})&1-2(q_{1}^{2}+q_{3}^{2})&2(q_{2}q_{3}-q_{0}q_{1})\\2(q_{1}q_{3}-q_{0}q_{2})&2(q_{0}q_{1}+q_{2}q_{3})&1-2(q_{1}^{2}+q_{2}^{2})\end{bmatrix}}}
The orthogonal matrix corresponding to a rotation with Euler angles
ϕ
,
θ
,
ψ
{\displaystyle \phi ,\theta ,\psi }
, with x-y-z convention, is given by[clarification needed ]
[
cos
θ
cos
ψ
−
cos
ϕ
sin
ψ
+
sin
ϕ
sin
θ
cos
ψ
sin
ϕ
sin
ψ
+
cos
ϕ
sin
θ
cos
ψ
cos
θ
sin
ψ
cos
ϕ
cos
ψ
+
sin
ϕ
sin
θ
sin
ψ
−
sin
ϕ
cos
ψ
+
cos
ϕ
sin
θ
sin
ψ
−
sin
θ
sin
ϕ
cos
θ
cos
ϕ
cos
θ
]
{\displaystyle {\begin{bmatrix}\cos \theta \cos \psi &-\cos \phi \sin \psi +\sin \phi \sin \theta \cos \psi &\sin \phi \sin \psi +\cos \phi \sin \theta \cos \psi \\\cos \theta \sin \psi &\cos \phi \cos \psi +\sin \phi \sin \theta \sin \psi &-\sin \phi \cos \psi +\cos \phi \sin \theta \sin \psi \\-\sin \theta &\sin \phi \cos \theta &\cos \phi \cos \theta \\\end{bmatrix}}}
Conversion
By combing the quaternion representations of the Euler rotations we get
q
=
R
z
(
ψ
)
R
y
(
θ
)
R
x
(
ϕ
)
=
[
cos
(
ψ
/
2
)
+
k
sin
(
ψ
/
2
)
]
[
cos
(
θ
/
2
)
+
j
sin
(
θ
/
2
)
]
[
cos
(
ϕ
/
2
)
+
i
sin
(
ϕ
/
2
)
]
{\displaystyle \mathbf {q} =R_{z}(\psi )R_{y}(\theta )R_{x}(\phi )=[\cos(\psi /2)+\mathbf {k} \sin(\psi /2)][\cos(\theta /2)+\mathbf {j} \sin(\theta /2)][\cos(\phi /2)+\mathbf {i} \sin(\phi /2)]}
q
=
[
cos
(
ϕ
/
2
)
cos
(
θ
/
2
)
cos
(
ψ
/
2
)
+
sin
(
ϕ
/
2
)
sin
(
θ
/
2
)
sin
(
ψ
/
2
)
sin
(
ϕ
/
2
)
cos
(
θ
/
2
)
cos
(
ψ
/
2
)
−
cos
(
ϕ
/
2
)
sin
(
θ
/
2
)
sin
(
ψ
/
2
)
cos
(
ϕ
/
2
)
sin
(
θ
/
2
)
cos
(
ψ
/
2
)
+
sin
(
ϕ
/
2
)
cos
(
θ
/
2
)
sin
(
ψ
/
2
)
cos
(
ϕ
/
2
)
cos
(
θ
/
2
)
sin
(
ψ
/
2
)
−
sin
(
ϕ
/
2
)
sin
(
θ
/
2
)
cos
(
ψ
/
2
)
]
{\displaystyle \mathbf {q} ={\begin{bmatrix}\cos(\phi /2)\cos(\theta /2)\cos(\psi /2)+\sin(\phi /2)\sin(\theta /2)\sin(\psi /2)\\\sin(\phi /2)\cos(\theta /2)\cos(\psi /2)-\cos(\phi /2)\sin(\theta /2)\sin(\psi /2)\\\cos(\phi /2)\sin(\theta /2)\cos(\psi /2)+\sin(\phi /2)\cos(\theta /2)\sin(\psi /2)\\\cos(\phi /2)\cos(\theta /2)\sin(\psi /2)-\sin(\phi /2)\sin(\theta /2)\cos(\psi /2)\\\end{bmatrix}}}
For Euler angles we get:
[
ϕ
θ
ψ
]
=
[
arctan
2
(
q
0
q
1
+
q
2
q
3
)
1
−
2
(
q
1
2
+
q
2
2
)
arcsin
(
2
(
q
0
q
2
−
q
3
q
1
)
)
arctan
2
(
q
0
q
3
+
q
1
q
2
)
1
−
2
(
q
2
2
+
q
3
2
)
]
{\displaystyle {\begin{bmatrix}\phi \\\theta \\\psi \end{bmatrix}}={\begin{bmatrix}{\mbox{arctan}}{\frac {2(q_{0}q_{1}+q_{2}q_{3})}{1-2(q_{1}^{2}+q_{2}^{2})}}\\{\mbox{arcsin}}(2(q_{0}q_{2}-q_{3}q_{1}))\\{\mbox{arctan}}{\frac {2(q_{0}q_{3}+q_{1}q_{2})}{1-2(q_{2}^{2}+q_{3}^{2})}}\end{bmatrix}}}
Relationship with Tait-Bryan angles
Similarly for Euler angles, we use the Tait-Bryan angles (in terms of flight dynamics ):
Roll -
ϕ
{\displaystyle \phi }
: rotation about the X-axis
Pitch -
θ
{\displaystyle \theta }
: rotation about the Y-axis
Yaw -
ψ
{\displaystyle \psi }
: rotation about the Z-axis
where the X-axis points forward, Y-axis to the right and Z-axis downward and in the example to follow the rotation occurs in the order yaw, pitch, roll (about body-fixed axes).
Nevertheless, it is not easy to find a matrix expression with Tait-Bryan angles because its final expression depends on how the rotations are applied.
Singularities
One must be aware of singularities in the Euler angle parametrization when the pitch approaches
±
90
o
{\displaystyle \pm 90^{o}}
(north/south pole). These cases must be handled specially. The common name for this situation is gimbal lock .
Code to handle the singularities is derived on this site: www.euclideanspace.com
See also