HOME

TheInfoList



OR:

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: :\mathbf = \begin q_0 & q_1 & q_2 & q_3 \end^T = \begin q_w & q_x & q_y & q_z \end^T :, \mathbf, ^2 = q_0^2 + q_1^2 + q_2^2 + q_3^2 = q_w^2 + q_x^2 + q_y^2 + q_z^2 = 1 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 :\mathbf_0 = \mathbf_w = \cos(\alpha/2) :\mathbf_1 = \mathbf_x = \sin(\alpha/2)\cos(\beta_x) :\mathbf_2 = \mathbf_y = \sin(\alpha/2)\cos(\beta_y) :\mathbf_3 = \mathbf_z = \sin(\alpha/2)\cos(\beta_z) 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: :\begin \mathbf_0 = \mathbf_w = \cos(\text/2)\\ \mathbf_1 = \mathbf_x = \sin(\text/2)\cos(\text)\\ \mathbf_2 = \mathbf_y = \sin(\text/2)\cos(\text)\\ \mathbf_3 = \mathbf_z = \sin(\text/2)\cos(\text)\end 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: :\begin \mathbf_0 = \mathbf_w = \cos(\alpha/2)\\ \mathbf_1 = \mathbf_x = \sin(\alpha/2)\cdot1\\ \mathbf_2 = \mathbf_y = \sin(\alpha/2)\cdot0\\ \mathbf_3 = \mathbf_z = \sin(\alpha/2)\cdot0\end 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: :\begin \mathbf_0 = \mathbf_w = \cos(\alpha/2)\\ \mathbf_1 = \mathbf_x = \sin(\alpha/2)\cdot0\\ \mathbf_2 = \mathbf_y = \sin(\alpha/2)\cdot1\\ \mathbf_3 = \mathbf_z = \sin(\alpha/2)\cdot0\end 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: :\begin \mathbf_0 = \mathbf_w = \cos(\alpha/2)\\ \mathbf_1 = \mathbf_x = \sin(\alpha/2)\cdot0\\ \mathbf_2 = \mathbf_y = \sin(\alpha/2)\cdot0\\ \mathbf_3 = \mathbf_z = \sin(\alpha/2)\cdot1\end 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: :\begin \mathbf_0 = \mathbf_w = \cos(\alpha/2)\\ \mathbf_1 = \mathbf_x = \sin(\alpha/2)\cdot0.707 \ldots\\ \mathbf_2 = \mathbf_y = \sin(\alpha/2)\cdot0.707 \ldots\\ \mathbf_3 = \mathbf_z = \sin(\alpha/2)\cdot0\end 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 – \psi: rotation about the Z-axis * Pitch – \theta: rotation about the new Y-axis * Bank – \phi: 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 ...
q=q_0+iq_1+jq_2+kq_3 is given by the inhomogeneous expression: :R = \begin 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 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: :R = \begin q_0^2 + q_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) & q_0^2 - q_1^2 + q_2^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) & q_0^2 - q_1^2 - q_2^2 + q_3^2 \end If q_0+iq_1+jq_2+kq_3 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: : \begin \begin x \\ y \\ z \\ \end & = R_z(\psi) R_y(\theta) R_x(\phi) \begin X \\ Y \\ Z \\ \end \\ & = \begin \cos\psi & -\sin\psi & 0 \\ \sin\psi & \cos\psi & 0 \\ 0 & 0 & 1 \\ \end \begin \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \\ \end \begin 1 & 0 & 0 \\ 0 & \cos\phi & -\sin\phi \\ 0 & \sin\phi & \cos\phi \\ \end \begin X \\ Y \\ Z \\ \end \\ & = \begin \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 \begin X \\ Y \\ Z \\ \end \\ \end


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): : \begin \mathbf & = \begin \cos (\psi /2) \\ 0 \\ 0 \\ \sin (\psi /2) \\ \end \begin \cos (\theta /2) \\ 0 \\ \sin (\theta /2) \\ 0 \\ \end \begin \cos (\phi /2) \\ \sin (\phi /2) \\ 0 \\ 0 \\ \end \\ & = \begin \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 \\ \end 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: :\begin \phi \\ \theta \\ \psi \end = \begin \mbox \left(\dfrac \right)\\ - \pi/2 + 2 \, \mbox \sqrt \\ \mbox \left(\dfrac \right) \end 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
: :\begin \phi \\ \theta \\ \psi \end = \begin \mbox \left(2(q_0 q_1 + q_2 q_3),1 - 2(q_1^2 + q_2^2)\right) \\ - \pi/2 + 2 \, \mbox \left(\sqrt, \sqrt\right) \\ \mbox \left(2(q_0 q_3 + q_1 q_2),1 - 2(q_2^2 + q_3^2)\right) \end Moreover, typical implementations of arctan also might have some numerical disadvantages near zero and one. Some implementations use the equivalent expression: : \theta = \mbox (2(q_0 q_2 - q_1 q_3))


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 q_0 and vector \vec such that \mathbf = (q_0,\vec) = q_0+iq_1+jq_2+kq_3. Note that the canonical way to rotate a three-dimensional vector \vec by a quaternion q defining an Euler rotation is via the formula :\mathbf^ = \mathbf^\ast where \mathbf = (0,\vec) = 0+iv_1+jv_2+kv_3 is a quaternion containing the embedded vector \vec, \mathbf^\ast=(q_0,-\vec) is a conjugate quaternion, and \mathbf^ = (0,\vec^) is the rotated vector \vec^. In computational implementations this requires two quaternion multiplications. An alternative approach is to apply the pair of relations :\vec = 2\vec \times \vec :\vec^ = \vec + q_0 \vec + \vec \times \vec where \times 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 : \begin \mathbf & = (r_1,\vec_1)(r_2,\vec_2) \\ & = (r_1 r_2 - \vec_1 \cdot \vec_2, r_1 \vec_2 + r_2 \vec_1 + \vec_1 \times \vec_2) \\ \end Using this relation one finds for \mathbf = (0,\vec) that : \begin \mathbf & = (0,\vec)(q_0,-\vec) \\ & = (\vec \cdot \vec, q_0 \vec - \vec \times \vec) \\ \end and upon substitution for the triple product : \begin \mathbf & = (q_0,\vec)(\vec \cdot \vec, q_0 \vec - \vec \times \vec) \\ & = (0, q_0^2 \vec + q_0 \vec \times \vec + (\vec \cdot \vec) \vec + q_0 \vec \times \vec + \vec\times(\vec\times\vec )) \\ \end where anti-commutivity of cross product and \vec\cdot \vec \times \vec = 0 has been applied. By next exploiting the property that \mathbf 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 q_0^2 = 1 - \vec\cdot\vec, along with the standard vector identity : \vec\times(\vec\times\vec) = (\vec\cdot\vec)\vec - (\vec\cdot\vec)\vec one obtains : \begin \mathbf^\prime & = \mathbf = (0, \vec + 2 q_0 \vec \times \vec + 2\vec\times (\vec\times\vec )) \\ \end which upon defining \vec = 2\vec \times \vec can be written in terms of scalar and vector parts as : (0, \vec^) = (0, \vec + q_0 \vec + \vec \times \vec ).


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