Spatial rotations in three dimensions can be
parametrized using both
Euler angles
The Euler angles are three angles introduced by Leonhard Euler to describe the orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189–207 (E478PDF/ref>
Th ...
and
unit quaternions. This article explains how to convert between the two representations. Actually this simple use of "quaternions" was first presented by
Euler
Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in ...
some seventy years earlier than
Hamilton Hamilton may refer to:
People
* Hamilton (name), a common British surname and occasional given name, usually of Scottish origin, including a list of persons with the surname
** The Duke of Hamilton, the premier peer of Scotland
** Lord Hamilto ...
to solve the problem of
magic square
In recreational mathematics, a square array of numbers, usually positive integers, is called a magic square if the sums of the numbers in each row, each column, and both main diagonals are the same. The 'order' of the magic square is the number ...
s. For this reason the dynamics community commonly refers to quaternions in this application as "Euler parameters".
Definition
For the rest of this article, the
JPL quaternion
In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined a quater ...
convention shall be used. A unit
quaternion
In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined a quater ...
can be described as:
:
:
We can associate a
quaternion
In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined a quater ...
with a rotation around an axis by the following expression
:
:
:
:
where α is a simple rotation angle (the value in radians of the
angle of rotation
In mathematics, the angle of rotation is a measurement of the amount, of namely angle, that a figure is rotated about a fixed point, often the center of a circle. A clockwise rotation is considered a negative rotation, so that, for instanc ...
) and cos(β
''x''), cos(β
''y'') and cos(β
''z'') are the "
direction cosine
In analytic geometry, the direction cosines (or directional cosines) of a vector are the cosines of the angles between the vector and the three positive coordinate axes. Equivalently, they are the contributions of each component of the basis to ...
s" of the angles between the three coordinate axes and the axis of rotation. (Euler's Rotation Theorem).
Intuition
To better understand how "
direction cosine
In analytic geometry, the direction cosines (or directional cosines) of a vector are the cosines of the angles between the vector and the three positive coordinate axes. Equivalently, they are the contributions of each component of the basis to ...
s" work with quaternions:
:
If the
axis of rotation
Rotation around a fixed axis is a special case of rotational motion. The fixed- axis hypothesis excludes the possibility of an axis changing its orientation and cannot describe such phenomena as wobbling or precession. According to Euler's r ...
is the ''x''-axis:
:
If the
axis of rotation
Rotation around a fixed axis is a special case of rotational motion. The fixed- axis hypothesis excludes the possibility of an axis changing its orientation and cannot describe such phenomena as wobbling or precession. According to Euler's r ...
is the ''y''-axis:
:
If the
axis of rotation
Rotation around a fixed axis is a special case of rotational motion. The fixed- axis hypothesis excludes the possibility of an axis changing its orientation and cannot describe such phenomena as wobbling or precession. According to Euler's r ...
is the ''z''-axis:
:
If the
axis of rotation
Rotation around a fixed axis is a special case of rotational motion. The fixed- axis hypothesis excludes the possibility of an axis changing its orientation and cannot describe such phenomena as wobbling or precession. According to Euler's r ...
is a
vector
Vector most often refers to:
*Euclidean vector, a quantity with a magnitude and a direction
*Vector (epidemiology), an agent that carries and transmits an infectious pathogen into another living organism
Vector may also refer to:
Mathematic ...
located 45° ( radians) between the ''x'' and ''y'' axes:
:
Therefore, the ''x'' and ''y'' axes "share" influence over the new
axis of rotation
Rotation around a fixed axis is a special case of rotational motion. The fixed- axis hypothesis excludes the possibility of an axis changing its orientation and cannot describe such phenomena as wobbling or precession. According to Euler's r ...
.
Tait–Bryan angles
Similarly for Euler angles, we use the
Tait Bryan angles (in terms of
flight dynamics
Flight dynamics in aviation and spacecraft, is the study of the performance, stability, and control of vehicles flying through the air or in outer space. It is concerned with how forces acting on the vehicle determine its velocity and attitude ...
):
* Heading –
: rotation about the Z-axis
* Pitch –
: rotation about the new Y-axis
* Bank –
: rotation about the new X-axis
where the X-axis points forward, Y-axis to the right and Z-axis downward. In the conversion example above the rotation occurs in the order heading, pitch, bank.
Rotation matrices
The
orthogonal matrix
In linear algebra, an orthogonal matrix, or orthonormal matrix, is a real square matrix whose columns and rows are orthonormal vectors.
One way to express this is
Q^\mathrm Q = Q Q^\mathrm = I,
where is the transpose of and is the identity m ...
(post-multiplying a column vector) corresponding to a clockwise/
left-handed
In human biology, handedness is an individual's preferential use of one hand, known as the dominant hand, due to it being stronger, faster or more dextrous. The other hand, comparatively often the weaker, less dextrous or simply less subject ...
(looking along positive axis to origin) rotation by the unit
quaternion
In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. Hamilton defined a quater ...
is given by the
inhomogeneous expression:
:
or equivalently, by the
homogeneous
Homogeneity and heterogeneity are concepts often used in the sciences and statistics relating to the uniformity of a substance or organism. A material or image that is homogeneous is uniform in composition or character (i.e. color, shape, siz ...
expression:
:
If
is not a unit quaternion then the homogeneous form is still a scalar multiple of a rotation matrix, while the inhomogeneous form is in general no longer an orthogonal matrix. This is why in numerical work the homogeneous form is to be preferred if distortion is to be avoided.
The direction cosine matrix (from the rotated Body XYZ coordinates to the original Lab xyz coordinates for a clockwise/lefthand rotation) corresponding to a post-multiply Body 3-2-1 sequence with
Euler angles
The Euler angles are three angles introduced by Leonhard Euler to describe the orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189–207 (E478PDF/ref>
Th ...
(ψ, θ, φ) is given by:
:
Euler angles (in 3-2-1 sequence) to quaternion conversion
By combining the quaternion representations of the Euler rotations we get for the Body 3-2-1 sequence, where the airplane first does yaw (Body-Z) turn during taxiing onto the runway, then pitches (Body-Y) during take-off, and finally rolls (Body-X) in the air. The resulting orientation of Body 3-2-1 sequence (around the capitalized axis in the illustration of Tait–Bryan angles) is equivalent to that of lab 1-2-3 sequence (around the lower-cased axis), where the airplane is rolled first (lab-x axis), and then nosed up around the horizontal lab-y axis, and finally rotated around the vertical lab-z axis (lB = lab2Body):
:
Other rotation sequences use different conventions.
Source code
Below code in C++ illustrates above conversion:
struct Quaternion
;
Quaternion ToQuaternion(double roll, double pitch, double yaw) // roll (x), pitch (Y), yaw (z)
Quaternion to Euler angles (in 3-2-1 sequence) conversion
A direct formula for the conversion from a quaternion to Euler angles in any of the 12 possible sequences exists. For the rest of this section, the formula for the sequence Body 3-2-1 will be shown.
If the quaternion is properly normalized, the Euler angles can be obtained from the quaternions via the relations:
:
However the
arctan
In mathematics, the inverse trigonometric functions (occasionally also called arcus functions, antitrigonometric functions or cyclometric functions) are the inverse functions of the trigonometric functions (with suitably restricted domains). Spe ...
functions implemented in computer languages only produce results between −π/2 and
π/2, to generate all the orientations one needs to replace the arctan functions in computer code by
atan2
In computing and mathematics, the function atan2 is the 2-argument arctangent. By definition, \theta = \operatorname(y, x) is the angle measure (in radians, with -\pi < \theta \leq \pi) between the positive :
:
Moreover, typical implementations of arctan also might have some numerical disadvantages near zero and one. Some implementations use the equivalent expression:
:
Source code
The following C++ program illustrates conversion above:
#define _USE_MATH_DEFINES
#include
struct Quaternion ;
struct EulerAngles ;
// this implementation assumes normalized quaternion
// converts to Euler angles in 3-2-1 sequence
EulerAngles ToEulerAngles(Quaternion q)
Singularities
One must be aware of singularities in the Euler angle parametrization when the pitch approaches ±90° (north/south pole). These cases must be handled specially. The common name for this situation is
gimbal lock
Gimbal lock is the loss of one degree of freedom in a three-dimensional, three-gimbal mechanism that occurs when the axes of two of the three gimbals are driven into a parallel configuration, "locking" the system into rotation in a degenerate t ...
.
Code to handle the singularities is derived on this site
www.euclideanspace.com
Vector rotation
Let us define scalar
and vector
such that
.
Note that the canonical way to rotate a three-dimensional vector
by a quaternion
defining an
Euler rotation is via the formula
:
where
is a quaternion containing the embedded vector
,
is a
conjugate quaternion, and
is the rotated vector
. In computational implementations this requires two quaternion multiplications. An alternative approach is to apply the pair of relations
:
:
where
indicates a three-dimensional vector cross product. This involves fewer multiplications and is therefore computationally faster. Numerical tests indicate this latter approach may be up to 30%
faster than the original for vector rotation.
Proof
The general rule for quaternion multiplication involving
scalar and vector parts is given by
:
Using this relation one finds for
that
:
and upon substitution for the triple product
:
where anti-commutivity of cross product and
has been applied. By next exploiting the property that
is a
unit quaternion
In mathematics, a versor is a quaternion of norm one (a ''unit quaternion''). The word is derived from Latin ''versare'' = "to turn" with the suffix ''-or'' forming a noun from the verb (i.e. ''versor'' = "the turner"). It was introduced by Will ...
so that
, along with the standard vector identity
:
one obtains
:
which upon defining
can be written in terms of scalar and vector parts as
:
See also
*
Rotation operator (vector space)
Rotation in mathematics is a concept originating in geometry. Any rotation is a motion of a certain space that preserves at least one point. It can describe, for example, the motion of a rigid body around a fixed point. Rotation can have sign ...
*
Quaternions and spatial rotation Unit quaternions, known as ''versors'', provide a convenient mathematical notation for representing spatial orientations and rotations of elements in three dimensional space. Specifically, they encode information about an axis-angle rotation abou ...
*
Euler Angles
The Euler angles are three angles introduced by Leonhard Euler to describe the orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189–207 (E478PDF/ref>
Th ...
*
Rotation matrix In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation in Euclidean space. For example, using the convention below, the matrix
:R = \begin
\cos \theta & -\sin \theta \\
\sin \theta & \cos \theta
\ ...
*
Rotation formalisms in three dimensions
In geometry, various formalisms exist to express a rotation in three dimensions as a mathematical transformation. In physics, this concept is applied to classical mechanics where rotational (or angular) kinematics is the science of quantitative ...
References
{{Reflist
External links
Q60. How do I convert Euler rotation angles to a quaternion?and related questions at The Matrix and Quaternions FAQ
Rotation in three dimensions
Euclidean symmetries
3D computer graphics
Quaternions