Rotation Representations and Their Conversions

A rigid body motion, which can be decomposed into rotation and translation, is essential for engineers and scientists who deal with moving systems in a space. While translation is as simple as vector addition, rotation is hard to understand because rotations are non-Euclidean, and there are many ways to represent them. Additionally, each representation comes with complex operations, and the conversions between different representations are not unique. Therefore, in this tutorial we review rotation representations which are widely used in industry and academia such as rotation matrices, Euler angles, rotation axis-angles, unit complex numbers, and unit quaternions. In particular, for better understanding we begin with rotations in a two dimensional space and extend them to a three dimensional space. In that context, we learn how to represent rotations in a two dimensional space with rotation angles and unit complex numbers, and extend them respectively to Euler angles and unit quaternions for rotations in a three dimensional space. The definitions and properties of mathematical entities used for representing rotations as well as the conversions between various rotation representations are summarized in tables for the reader’s later convenience.


I. INTRODUCTION
Kinematics is fundamental to understand how a rigid body has moved in a space and thus widely applied in physics [1], control [2], robotics [3], computer vision [4] and computer graphics [5]. For example, it is used to calculate the pose of the end effector when each joint of a manipulator is rotated by some angle, to estimate the trajectory of an autonomous vehicle when it moves in an environment and observes some landmarks in the map, and to interpolate the character animation between keyframes in a virtual world.
Meanwhile, a rigid body motion is decomposed into rotation and translation, where translation is as simple as vector addition, but it is not straightforward to understand rotations because rotations are non-Euclidean, and there are many representations. There are some materials for rotation representations for engineers and scientists [6], [7], [8], [9]. However, they only consider a three dimensional case or focus on specific representations without converting between different representations.
The associate editor coordinating the review of this manuscript and approving it for publication was Derek Abbott . In this tutorial, we explain various rotation representations such as rotation matrices, Euler angles, rotation axis-angles, unit complex numbers and unit quaternions as shown in Figure 1. In particular, for better understanding we first review rotations in a two dimensional space and extend them to a three dimensional space. In that context, we learn rotation angles, 2 × 2 rotation matrices and unit complex numbers for rotations in a two dimensional space, and extend them to Euler angles, rotation axis-angles, 3 × 3 rotation matrices and unit quaternions for rotations in a three dimensional space. To the best knowledge of authors this is our uniqueness to explain various rotation representations. For the reader's convenient usage, we summarize the definitions and properties of mathematical entities for rotation representations and the conversions between different rotation representations in tables. This is an extended version of our previous work written in Korean [10].
The structure of this paper is as follows. The outline is described, and the notations are clarified in Section II. We begin with rotations in a two dimensional space in Section III and extend them to rotations in a three dimensional space in Section IV. We discuss the advantages and disadvantages of various representations in Section V. Finally, we conclude the paper in Section VI.

II. OVERVIEW
A. OUTLINE Figure 1 depicts rotation representations described in this tutorial. For rotations in a two dimensional space, we first learn how to rotate a point given a rotation angle and introduce a rotation matrix by applying the matrix-vector multiplication in Section III-A. After reviewing the definition and properties of complex numbers, we learn how to convert a pure complex number to a unit complex number using the exponential map or so-called Euler's formula, and show that a unit complex number can be used to rotate a point by using complex number multiplication in Section III-B.
On the other hand, for rotations in a three dimensional space, we extend rotation angles to Euler angles for the standard basis vectors in Section IV-A and further extend to rotation axis-angles for arbitrary rotation axes in Section IV-B. Here, we introduce Rodrigues' formula which is a fundamental equation for rotations in a three dimensional space. Finally, we extend complex numbers to quaternions and show that a unit quaternion can be used to rotate a point in a three dimensional space by using quaternion conjugation in Section IV-C. Table 1 summarizes notations used in this tutorial. Mathematical entities introduced in this tutorial are distinguished by fonts as well as alphabets. Scalars are denoted by lowercase italics letters (e.g. x, y, z, and w), vectors by lowercase boldface letters (e.g. v), and matrices by uppercase boldface letters (e.g. R for rotation matrices). Both complex numbers and quaternions are denoted by lowercase italics letters (e.g., z for complex numbers and q for quaternions). Particularly, conjugate complex numbers and conjugate quaternions are denoted by different symbols such as a bar and an asterisk (e.g.z and q * ). Unit entities such as unit vectors, unit complex numbers and unit quaternions are all denoted by a caret (e.g.v,ẑ, andq).

B. NOTATIONS
In case that alphabets and fonts are not enough to distinguish a mathematical entity, or when we want to make it clear which entity it is, we specify which number set it belongs to. For instance, the scalar, vector, and matrix sets are denoted by R with dimensions in superscript. The complex number set is denoted by C, the unit complex number set by S 1 , and the pure complex number set by I. On the other hand, the quaternion set is denoted by H, the unit quaternion set by S 3 , and the pure quaternion set by V.

III. 2D ROTATIONS
A rotation in a two dimensional space is very simple because it has only one degree of freedom; the rotation angle. In this section, we will show that a 2 × 2 matrix and a unit complex number can also represent a rotation in a two dimensional space. We will extend what we have learned in this section to rotations in a three dimensional space in the next section. We will also discover that one of the main differences between 2D and 3D rotations is that 2D rotations commute, while 3D rotations do not commute with each other.

A. ROTATION MATRICES
We will first review the relationship between two points before and after a rotation in a two dimensional space. By expressing it in a matrix-vector multiplication, we will show that a 2 × 2 matrix can represent a rotation in a two dimensional space. a: FORWARD ROTATIONS Figure 2 shows a rotation in a two dimensional space where a vector p = [x, y] ⊤ is rotated counterclockwise by an angle θ and transformed to a vector p ′ = [x ′ , y ′ ] ⊤ . The vector p is of length r and makes an angle φ with the positive x-axis. Thus, the coordinates of two vectors p and p ′ are .
(1) VOLUME 11, 2023 From the trigonometric angle addition theorem, the equation on the right can be simplified as Therefore, the rotated vector p ′ can be calculated by a multiplication between a matrix R and a vector p, where the rotation matrix R ∈ R 2×2 is defined as Note that the column vectors of the rotation matrix are the standard basis vectors of the rotated frame as shown in Figure 2b. Therefore, a rotation matrix can represent either a rotation of points or an orientation of a moving frame. Also note that the determinant of the rotation matrix is equal to one, det(R) = 1, and thus it does not stretch, shrink or reflect, but rotates a vector space. Equation (4) describes the conversion from a rotation angle to a rotation matrix, the arrow ① in Figure 1.
Inversely, from Equation (4) we can extract the rotation angle θ given a rotation matrix R as where r ij ∈ R is the element of the i-th row and the j-th column of the matrix R, and the function atan2(y, x) returns the angle that the vector [x, y] ⊤ makes with the positive x-axis. Note that Equation (5) describes the conversion from a rotation matrix to a rotation angle, the arrow ② in Figure 1. For later use in Section IV-B, let us rewrite Equation (2) by substituting the perpendicular vector w = [−y, x] ⊤ as In other words, in a two dimensional space the rotated vector can be calculated when the original vector, its perpendicular vector and the rotated angle are given.

b: INVERSE ROTATIONS
By changing the sign of the angle in Equation (4), we can easily see that the inverse of a rotation matrix is equal to its transpose c: COMPOSITION OF ROTATIONS Given two 2D rotations by angles θ 1 and θ 2 , we can represent them as rotation matrices R 1 , R 2 ∈ R 2×2 , Then, from Equation (3) the rotation by the angle θ 1 followed by another rotation by the angle θ 2 denoted as R 12 ∈ S 1 is equal to the multiplication of corresponding rotation matrices, Note that the order of multiplications for the composition of rotations is from right to left. The properties of 2 × 2 rotation matrices are summarized in the second column of Table 2.

B. UNIT COMPLEX NUMBERS
Before we move on to unit complex numbers, let us define complex numbers and review the properties of their operations. Then, we will show that a unit complex number can represent a rotation in a two dimensional space, and the rotated vector can be calculated by a complex number multiplication.

1) DEFINITION OF IMAGINARY NUMBERS
Let us define the unit imaginary number i ∈ S 1 , I as Then, its multiples with an arbitrary real number become imaginary numbers of which squares are negative.

2) DEFINITION OF COMPLEX NUMBERS
A complex number z ∈ C is defined as a summation of both real and imaginary numbers, where x, y ∈ R are called the real and imaginary parts respectively, and expressed as When the imaginary part is zero, the complex number turns to a real number. Therefore, the set of complex numbers includes the set of real numbers as shown in Figure 3. When the real part is zero, on the other hand, it is called a purely imaginary number or a pure complex number. The complex conjugatez ∈ C is defined by changing the sign of the imaginary part,  Thus, it is natural that conjugating twice gives the original complex number back, As shown in Figure 4, a complex number z = x + iy ∈ C corresponds to a point (x, y) ∈ R 2 or to a vector from the origin to that point. Then, the complex conjugatez corresponds to the reflection of z about the real axis.

3) OPERATIONS OF COMPLEX NUMBERS a: ADDITION
Given complex numbers z 1 , z 2 , z 3 ∈ C, the addition of two complex numbers is done by adding their real and imaginary parts separately, which is similar to the vector addition. Hence, the complex number addition is commutative, Also, the complex number addition is associative, Moreover, the conjugate of the sum of two complex numbers is equal to the sum of their complex conjugates, The multiplication of two complex numbers is equal to by the definition of the imaginary number in Equation (10). Thus, the complex number multiplication is commutative, Also, the complex number multiplication is associative, Moreover, one can easily prove that the conjugate of the multiplication of two complex numbers is equal to the multiplication of their complex conjugates,

c: MAGNITUDE
The magnitude of a complex number z = x + iy ∈ C is defined as the length of the corresponding vector as shown in Figure 4, Thus, the magnitudes of a complex number and its conjugate are the same, Also, the multiplication of a complex number and its conjugate is equal to the square of their magnitudes, From Equation (20) and (24), the magnitude of the multiplication of two complex numbers is equal to the multiplication of their magnitudes, By the way, similar to vectors, a unit complex number z ∈ S 1 is defined as a complex number of the unit magnitude, ∥ẑ∥ = 1. (28)

d: INVERSION
Similar to real numbers, the multiplication of a complex number z ∈ C and its inversion z −1 ∈ C is defined to be identity, Thus, by multiplying both the numerator and denominator with its complex conjugate and applying Equation (26), Equation (29) can be rewritten as Thus, the inverse of a unit complex number is equal to its complex conjugate,ẑ The operation properties of complex numbers are summarized in Table 3.

4) EXPONENTIAL AND LOGARITHMIC MAPS
So far we have reviewed the definition of complex numbers and their properties, and learned that a complex number corresponds to a vector in a two dimensional space. Now, let us turn our attention to a unit complex number to represent a rotation in a two dimensional space.

a: POWERS OF UNIT IMAGINARY NUMBER
It is easy to show that the powers of the unit imaginary number i ∈ S 1 , I cycle through a sequence as below, In other words, every time we multiply the unit imaginary number i to a complex number (e.g., z = 1 ∈ C in this case), it rotates counter-clockwise by 90 • as shown in Figure 5.

b: EXPONENTIAL MAP OF PURE COMPLEX NUMBERS
In order to show the relation between the unit imaginary number i and 2D rotations, let us review the Taylor series of a function. For a real-valued function f (x) that is infinitely differentiable at x = a, its Taylor series at x = a is Then, the Taylor series of the function e x at x = 0 is Also, for the trigonometric function sin x and cos x, their Taylor series at x = 0 are Therefore, by substituting x = iθ ∈ I in Equation (34) and applying Equation (32), (35) and (36), we obtain Euler's formula, which is called an exponential map from a pure complex number to a unit complex number. One may extend this to an exponential map from a complex number to a complex number, but it is beyond the scope of this tutorial.

c: LOGARITHMIC MAP OF UNIT COMPLEX NUMBERS
The inverse map of Equation (37) is a logarithm map from a unit complex numberẑ ∈ S 1 to a pure complex number, logẑ = iθ, θ = atan2(Im(ẑ), Re(ẑ)).
Note that θ and θ ± 2nπ, where n is a natural number, represent the same orientation. Therefore, to avoid ambiguity we set the range of the angle θ to (−π, π]. More details on ambiguity will be discussed in Section V. One may extend this to a logarithm map from a complex number to a complex number. Instead, we review the polar representation of a complex number in the following.

d: POLAR REPRESENTATIONS
For a complex number z = x + iy, it can be rewritten as where the magnitude r and the angle θ are from Equation (37) and (38), This is called the polar representation of a complex number.
In other words, a complex number is defined with a magnitude from the origin and an angle from the real axis. Assume that two complex numbers z 1 , z 2 ∈ C are given in a polar representation, Then, the magnitude and angle of their multiplication are equal to the multiplication of their magnitudes and the sum of their angles, respectively, Note that this agrees with the logarithmic product rule for unit complex numbers of Equation (38).

5) UNIT COMPLEX NUMBERS FOR 2D ROTATIONS
Finally, let us focus on how to represent a rotation in a two dimensional space with a unit complex number and how to calculate the rotated vector using complex number multiplication.

a: FORWARD ROTATIONS
Let us first convert a vector p = [x, y] ⊤ in Figure 2 to a complex number p ∈ C, Also, let us convert a rotation angle θ to a unit complex numberẑ ∈ S 1 using the exponential map of Equation (37), Then, the complex number p ′ ∈ C corresponding to the rotated vector p ′ = [x ′ , y ′ ] ⊤ can be calculated by a complex number multiplication, One can easily prove this by comparing the real and imaginary parts of Equation (45) with the vector components in Equation (2). With a polar representation, it is clear that the result of Equation (45) is exactly the rotated vector. As shown in Figure 2, suppose that the original vector p = [x, y] ⊤ has a length of r and makes an angle φ with the positive x-axis. Then, its corresponding complex number p ∈ C in Equation (43) can be rewritten as Also, the unit complex numberẑ ∈ S 1 in Equation (44) can be converted to a polar representation, Thus, substituting Equation (46) and (47) in Equation (45) gives which corresponds to the rotated vector p ′ = [x ′ , y ′ ] ⊤ with the same length r, making an angle φ + θ with the positive x-axis.
Therefore, you can say that the exponential map of Equation (44) describes the conversion from a rotation angle to a unit complex number, the arrow ③ in Figure 1a. Conversions between various rotation representations in a two dimensional space. The first column is converted to other columns numbered by the arrows in Figure 1. Note that the special cases are omitted for brevity. Refer to the main text for details.
Inversely, the logarithm map of Equation (38) explains the conversion from a unit complex number to a rotation angle, the arrow ④ in Figure 1.
For the conversion between a unit complex number and a rotation matrix, suppose that a unit complex numberẑ ∈ S 1 is given asẑ Substituting it in Equation (45) gives Thus, by pulling out the original vector p = [x, y] ⊤ in the right-hand side of Equation (50), we can rewrite it similar to Equation (3) and obtain the rotation matrix R ∈ R 2×2 as In other words, Equation (51) denotes the conversion from a unit complex number to a rotation matrix, the arrow ⑤ in Figure 1. Inversely, from Equation (51) the conversion from a rotation matrix to a unit complex number, the arrow ⑥ in Figure 1 is calculated byẑ Given 2D rotations by angles θ 1 and θ 2 , we can represent them as unit complex numbersẑ 1 ,ẑ 2 ∈ S 1 , Then, from Equation (45) the rotation by the angle θ 1 followed by another rotation by the angle θ 2 denoted asẑ 12 ∈ S 1 equals to the multiplication of corresponding unit complex numbers aŝ Note that the order of multiplications for the composition of rotations is from right to left, which is similar to the rotation matrix case. However, the multiplication of two complex numbers is commutative. Thus, the order does not matter.
In conclusion of this section on 2D rotations, the properties of unit complex numbers are summarized in the third column of Table 2, and the conversions between various rotation representations in a two dimensional space are summarized in Table 4.

IV. 3D ROTATIONS
Let us turn our attention to rotations in a three dimensional space. Unlike a two dimensional case, now we can rotate a point about three axes, x, y, and z, which can be represented as Euler angles or roll-pitch-yaw. Alternatively, we can rotate a point about an arbitrary axis by an angle, which is represented as an rotation axis-angle. Finally, a rotation in a three dimensional space can be represented as a unit quaternion which is extended from a unit complex number.

A. EULER ANGLES AND ROLL-PITCH-YAW
Euler angles and roll-pitch-yaw are used to describe an orientation of a coordinate system. Thus, one might think that rotating a point and rotating a coordinate system are different, and so they are not relevant to the topic of this tutorial. However, as mentioned in Section III-A and Figure 2b, changing coordinates from a rotated frame to the original frame and rotating a point are mathematically equivalent. Figure 6a shows the rotation angles α, β and γ with respect to each of the x, y, and z-axes, and Figure 6b shows the case of rotating the frame about the z-axis by an angle γ . By collecting the standard basis vectors of the rotated frame, we can construct the rotation matrix about the z-axis. Note that the rotation in the xy plane is same as in Figure 2b, and so the top-left sub-matrix of Equation (56) is same as Equation (4).

1) BASIC ROTATION MATRICES
For a rotation about the x-axis, changing the x, y, and z axes in Figure 6b to the y, z and x axes respectively gives the corresponding rotation matrix, Similarly, for a rotation about the y-axis, changing the x, y, and z axes in Figure 6b to the z, x and y axes respectively gives the corresponding rotation matrix, Now, we have rotation matrices for the basic rotations and are ready to combine them for Euler angles and roll-pitchyaw angles.

2) EULER ANGLES a: TO ROTATION MATRIX
It is important that Euler angles rotate a coordinate frame with respect to the moving frame [2], [11], [12]. Thus, one rotation occurs before another rotation, and so we multiply corresponding rotation matrices from left to right (postmultiplication). For example, when we rotate a coordinate frame about the x-axis, then about the current y-axis, and finally about the current z-axis, we get the rotation matrix of the XYZ order, where s and c are short for the sin and cos functions, and the subscripts are their input angles (e.g., s α = sin α).
For rotations in a three dimensional space, we can permute three different rotations such as XYZ and ZYX (6 permutations), or combine only two different rotations in one of the planes such as XYX and ZYZ (6 cases). Thus, there are 12 possible angle sequences in total for Euler angles, but we only consider the XYZ order in this tutorial.
Note that Equation (59) converts Euler angles to a rotation matrix, which is the arrow ⑦ in Figure 1.

b: FROM ROTATION MATRIX
Inversely, given a rotation matrix R ∈ R 3×3 as in Equation (59), if r 13 ̸ = ±1 (i.e., cos β ̸ = 0), the Euler angles can be extracted from the first row and the last column as where the inverse of the sin function, asin, is used because atan2 is numerically unstable where the first argument is near zero and one [6].
On the other hand, if r 13 = ±1 (i.e., cos β = 0), the first row and the last column except r 13 are filled with 0s. Thus, setting sin β = ±1 in the 2 × 2 sub-matrix at the bottomleft corner gives 4 equations for each case, which can be simplified by the trigonometric addition formulas and gives many solutions as From Equation (60) and (61) it is obvious that there is no unique solution for the arrow ⑧ which converts a rotation matrix to Euler angles.

c: GIMBAL LOCK
It is well known that Euler angles suffer from the gimbal lock problem, where two rotation axes become parallel and one degree of freedom is lost.
For example, when β = π 2 , Equation (59) becomes Now, it has only one degree of freedom left so that it locks the system into a degenerate two-dimensional space. Note that Equation (61) tells that the rotations about the x-axis and the z-axis are now equivalent because their rotation axes in the gimbal are parallel to each other. The gimbal lock problem leads to the singularity issue of Euler angles. More details on singularity will be discussed in Section V. VOLUME 11, 2023 FIGURE 7. Rotation about an arbitrary axis. A vector p is rotated about an axisv of a unit vector by an angle θ and transformed to the vector p ′ . The vector p is decomposed into two orthogonal vectors, p ∥ and p ⊥ which are parallel to and perpendicular to the rotation axisv, respectively. The vector w is perpendicular to the vector p ⊥ after rotating 90 • about the rotation axisv.

3) ROLL-PITCH-YAW
Besides Euler angles, roll-pitch-yaw angles are widely used to specify the orientation of aircrafts, where the x-axis is toward the heading direction, the y-axis is toward the right wing, and the z-axis is toward the bottom.
Unlike Euler angles, roll-pitch-yaw angles rotate a coordinate frame with respect to the fixed frame [2], [11], [12]. Thus, mathematically one rotation occurs after another rotation, and so we multiply corresponding rotation matrices from right to left (pre-multiplication). For example, when we rotate a coordinate frame about the x-axis, then about the fixed y-axis, and finally about the fixed z-axis, we get the rotation matrix of the ZYX order, Note that even though the rotation order is the same, i.e., x, y, and then z, the direction of the matrix multiplication for roll-pitch-yaw angles (ZYX) is opposite to that of Euler angles (XYZ). Equation (63) converts roll-pitch-yaw angles to a rotation matrix. Similarly to Euler angles, we can extract roll-pitchyaw angles from a rotation matrix, but it is omitted for the sake of paper length and also in Figure 1b. Meanwhile, just like Euler angles, it is straightforward that roll-pitch-yaw angles suffer from the gimbal lock problem.

B. AXIS-ANGLES
In case of Euler angles and roll-pitch-yaw angles, we only rotate about the standard basis vectors. However, in a three dimensional space we can also rotate about an arbitrary vector by an angle and so represent it with the rotation axis and angle. Figure 7 shows a rotation about an arbitrary axis. A vector p is rotated about an axisv by an angle θ, and transformed to the vector p ′ . Note that since we only need the direction for the rotation axis, not the magnitude, the rotation axisv is normalized as a unit vector of length 1.

1) RODRIGUES' FORMULA
First, let us decompose the vector p into two orthogonal vectors, p ∥ and p ⊥ which are parallel to and perpendicular to the rotation axisv, respectively.
The parallel vector p ∥ does not change due to the rotation, while the perpendicular vector p ⊥ is transformed to its rotated vector p ′ ⊥ . Thus, we can similarly decompose the rotated vector p ′ as Here, the parallel vector p ∥ is the projection of the original vector p to the rotation axisv of a unit vector, On the other hand, the vector w is perpendicular to both the rotation axisv and the original vector p, w =v × p.
As shown in Figure 7b, the perpendicular vector p ⊥ is rotated to the vector p ′ ⊥ in a two dimensional plane, just like in Figure 2. Thus, from Equation (6) p ′ ⊥ = p ⊥ cos θ + w sin θ.

2) TO ROTATION MATRIX
Let us simplify Equation (69) by pulling out the original vector p from the right-hand side and making a form of the matrix-vector multiplication like Equation (3) as where the rotation matrix R ∈ R 3×3 is defined as [11] Here, [·] × ∈ R 3×3 denotes a skew-symmetric matrix which turns a cross product between two vectors into a matrixvector multiplication. In other words, for the vectorv = [v x , v y , v z ] ⊤ , its skew-symmetric matrix is For a sanity check, if we setv = [0, 0, 1] ⊤ , then Equation (71) reduces to Equation (56) which is the rotation matrix about the z-axis.
Equation (71) describes the conversion from a rotation axis-angle to a rotation matrix, the arrow ⑨ in Figure 1b. For reference, a rotation vector r ∈ R 3 is defined as the vector with the same direction of the rotation axisv and the magnitude of the rotation angle θ,
Here,v and −v represents the same orientation when the rotation angle θ = π, and thus there is ambiguity. Equation (74), (75) and (76) describe the conversion from a rotation matrix to a rotation axis-angle, the arrow ⑩ in Figure 1b.
It is worthwhile to mention that in some programming libraries such as Matlab [14] and Spatial Math [15], a rotation matrix is directly converted to a rotation axis-angle using Equation (76). However, in other libraries such as Eigen [16], a rotation matrix is indirectly converted to a rotation axisangle via a unit quaternion for stability.

C. UNIT QUATERNIONS
Finally, let us extend complex numbers in Section III-B to quaternions and review the properties of their operations. As a result, we'll show that a unit quaternion can represent a rotation in a three dimensional space, and the rotated vector can be calculated by a quaternion conjugation.

1) EXTENSION OF IMAGINARY NUMBERS
For 2D rotations a single imaginary number i ∈ S 1 , I is enough. However, for 3D rotations three imaginary numbers i, j, k ∈ S 3 , V are required as which is well known to be discovered by William Rowan Hamilton when he was walking on the Broom Bridge in the mid-19th century [17]. It is very important that the multiplications between the extended imaginary numbers are not commutative. Thus, from Equation (77) the following holds

2) DEFINITION OF QUATERNIONS
A quaternion q ∈ H is defined as a summation of both real and imaginary numbers, where the components of the 4-tuple are w, x, y, z ∈ R. Note that when y = z = 0, it reduces to a complex number. Thus, the set of quaternions H includes the set of complex numbers C as shown in Figure 3. Also, when w = 0, it is called a pure quaternion which corresponds to a vector in a three dimensional space. A quaternion can also be rewritten as a sum of a real number w ∈ R and a pure quaternion v = ix + jy + kz ∈ V, where w and v are called the scalar and vector parts respectively, and expressed as The conjugate q * ∈ H of a quaternion q is defined by reversing the sign of the vector part, Thus, similarly to complex numbers, conjugating twice turns back to the original quaternion,
Thus, the addition of two quaternions is commutative, which is similar to the addition of two complex numbers. VOLUME 11, 2023 Also, the addition of quaternions is associative, Moreover, the conjugate of the sum of quaternions is equal to the sum of their conjugates, which is also similar to the case of complex numbers.

b: MULTIPLICATION OF PURE QUATERNIONS
Before we move on to the multiplication of two quaternions, let us first think about a special case, the multiplication of two which are in fact the vector parts of two quaternions in Equation (84).
As the name implies, let us define the dot and cross products of the vector parts of two quaternions. The dot product of two pure quaternions is defined as On the other hand, the cross product of two pure quaternions is defined as which is again a pure quaternion. Note that both the dot and cross products of two pure quaternions are quite similar to those of three dimensional vectors. Thus, they are commutative and anti-commutative, respectively, Then, the multiplication of two pure quaternions is simplified with their dot and cross products as which is not commutative in general. With Equation (93) one can further rewrite the dot and cross products of pure quaternions as Now, let us think about a general case. Given two quaternions as in Equation (84), their multiplication is which can be further simplified by applying Equation (93) Note that if we set w 1 = w 2 = 0, Equation (96) reduces to Equation (93). Note that unlike complex numbers, the multiplication of two quaternions is not commutative which is originally because the multiplications of extended imaginary numbers are not commutative as in Equation (78). However, the multiplication of quaternions is associative, Moreover, one can easily prove that the conjugate of the multiplication of two quaternions equals the multiplication of their conjugates, but with the order reversed, The magnitude of a quaternion q = w + ix + jy + kz ∈ H is defined as the length of the corresponding 4D vector, Thus, the magnitudes of a quaternion and its conjugate are the same, Also, the multiplication of a quaternion and its conjugate is equal to the square of their magnitude, Moreover, the magnitude of the multiplication of two quaternions is equal to the multiplication of their magnitudes, By the way, similar to vectors, a unit quaternionq ∈ S 3 is defined as a quaternion of the unit magnitude, Similar to real numbers, the multiplication of a quaternion q ∈ H and its inversion q −1 ∈ H is defined to be identity, Thus, multiplying both the numerator and denominator with its conjugate and applying Equation (102) gives Thus, the inverse of a unit complex number is equal to its conjugate,q −1 =q * . (107) The operation properties of complex numbers and quaternions are compared in Table 3.

4) EXPONENTIAL AND LOGARITHMIC MAPS
So far, we have reviewed the definition of quaternions and their properties, and learned that a pure quaternion corresponds to a vector in a three dimensional space. Now let us turn our attention to how to represent a rotation in a three dimensional space using a unit quaternion.

a: POWERS OF UNIT PURE QUATERNIONS
Like the unit imaginary number i ∈ S 1 , I, the powers of a unit pure quaternionv ∈ S 3 , V cycle through a sequence, which is becausev 2 = −1 from Equation (93). In other words, every time we multiply the unit pure quaternionv to a quaternion (e.g., q = 1 ∈ H in this case), it rotates counterclockwise as shown in Figure 5. Thus, it implies that the unit pure quaternionv has something to do with rotations in a three dimensional space.

b: EXPONENTIAL MAP OF PURE QUATERNIONS
Now, let us extend Euler's formula for pure quaternions. Substituting x with a pure quaternion (i.e., x =vφ ∈ V) in the Taylor series of Equation (34) and applying the repetition property of the powers of unit pure quaternions of Equation (108) gives which is called the exponential map from a pure quaternion to a unit quaternion. One may extend this to the exponential map from a quaternion to another quaternion, but it is beyond the scope of this tutorial.

c: LOGARITHM MAP OF UNIT QUATERNIONS
The inverse map of Equation (109) is a logarithm map from a unit quaternionq ∈ S 3 to a pure quaternion, When the denominator ∥V (q)∥ = 0, it means V (q) = 0, which is a pure quaternion. Thus, the unit quaternionq = 1, and its logarithm becomes zero. Note that with the same rotation axis, φ and φ ± 2nπ where n is a natural number, represent the same orientation. Therefore, we set the range of the angle φ to (−π, π] to avoid ambiguity. One may extend this to the logarithm map from a quaternion to another quaternion, but we skip that in this tutorial.

5) UNIT QUATERNIONS FOR 3D ROTATIONS
Now, let us focus on how to represent a rotation in a three dimensional space with a unit quaternion and how to calculate the rotated vector using quaternion conjugation.

a: FORWARD ROTATIONS
Let us convert a vector p = [x, y, z] ⊤ in Figure 7 to a pure quaternion p ∈ V, Also, let us convert the rotation axis expressed with a unit vectorv From Equation (109) we can represent the rotation about the rotation axisv by an angle θ as a unit quaternionq ∈ S 3 , Note that we are using the half angle here. Then, the pure quaternion p ′ ∈ V corresponding to the rotated vector p ′ = [x ′ , y ′ , z ′ ] ⊤ is calculated by evaluating the conjugation of the pure quaternion p by the unit quaternionq as One can easily prove this by comparing each component of the pure quaternion in Equation (114) with the vector components of Equation (69). For 2D rotations, the rotation axis becomes the z-axis, and thus Equation (114) can be rewritten aŝ q = cos θ 2 + k sin θ 2 (ix + jy) cos θ 2 −k sin θ 2 = i(x cos θ − y sin θ) + j(x sin θ + y cos θ), (115) which is the same as Equation (2) and Equation (45). Therefore, Equation (114) represents a unified approach to rotations, applicable in both 2D and 3D. Note that substitutingq with −q in Equation (114) gives the same result, which means that they represent the same rotation. Therefore, we can restrict unit quaternions to one hemisphere of the 3-sphere, S 3 , which can be done by having non-negatives for the scalar part of the unit quaternions.
By the way, if we rewrite the unit quaternionq in Equation (113) with its scalar and vector parts aŝ where w = cos θ 2 and v =v sin θ 2 . Using Equation (93), Equation (114) can be rewritten as Equation (117) looks more complex than Equation (114), but in fact it involves fewer operations. So, it is commonly used for rotating a vector using a unit quaternion. More details will follow in Section V. Given two rotations about rotation axesv 1 ,v 2 ∈ R 3 by angles θ 1 and θ 2 represented as unit quaternionsq 1 ,q 2 ∈ S 3 , the rotation about the rotation axisv 1 by the angle θ 1 first followed by another rotation about the rotation axisv 2 by the angle θ 2 denoted asq 12 ∈ S 3 is equal to their multiplication from Equation (114), Note that the multiplication of two quaternions is not commutative, and the order of multiplications for the composition of rotations is from right to left, which is similar to the rotation matrix case. The properties of unit quaternions are summarized in the fifth column of Table 2.
It is worthwhile to mention that in some programming libraries such as Sophus [18], a rotation or an orientation in a three dimensional space is internally implemented with a quaternion. Even though it is not intuitive and needs four redundant variables, it does not suffer from the gimbal lock problem. Moreover, the computations required for rotating points, composing rotations and inverting rotations are relatively simple.

d: CONVERSION BETWEEN UNIT QUATERNION AND AXIS-ANGLE
The exponential map with a half angle in Equation (113) describes the conversion from a rotation axis-angle to a unit quaternion, the arrow 11 ⃝ in Figure 1b. Inversely, its logarithm map for the unit quaternion iŝ which explains the conversion from a unit quaternion to a rotation axis-angle, the arrow 12 ⃝ in Figure 1b. If ∥V (q)∥ = 0 (i.e.,q = 1), the rotation angle is zero, and the rotation axis is an arbitrary unit vector.

e: CONVERSION BETWEEN UNIT QUATERNION AND ROTATION MATRIX
For the conversion between a unit quaternion and a rotation matrix, suppose a unit quaternionq ∈ S 3 is given aŝ By substituting it in Equation (114) and pulling out p = [x, y, z] ⊤ , we can rewrite it similar to Equation (70) and obtain the rotation matrix R ∈ R 3×3 as R=   1−2(q 2 y + q 2 z ) 2(q x q y −q w q z ) 2(q x q z +q w q y ) 2(q y q x +q w q z ) 1−2(q 2 x + q 2 z ) 2(q y q z −q w q x ) 2(q z q x −q w q y ) 2(q z q y +q w q x ) 1−2(q 2 In other words, Equation (123) denotes the conversion from a unit quaternion to a rotation matrix, the arrow 13 ⃝ in Figure 1b. Inversely, from Equation (123) the scalar part of the unit quaternion can be calculated from the diagonal part as If q w ̸ = 0 (in reality, tr(R) > 0 for numerical stability), the unit quaternion is Otherwise, we look for the maximum diagonal element for numerical stability and calculate the unit quaternion [19].

f: CONVERSION BETWEEN UNIT QUATERNION AND EULER ANGLES
Given Euler angles, α, β, and γ for the x, y, and z axes respectively, each basic rotation can be converted to unit quaternionsq x ,q y ,q z ∈ S 3 from Equation (113) as (129) 6694 VOLUME 11, 2023 Conversions between various rotation representations in a three dimensional space. The first column is converted to other columns numbered by the arrows in Figure 1a. Note that the special cases are omitted for brevity. Here, s and c are short for the sin and cos functions, and their subscripts are input angles. Refer to the main text for details.
Thus, the corresponding unit quaternionq = q w +iq x +jq y + kq z ∈ S 3 is equal to which is becauseq =q xqyqz .
For the special case of 2(q x q z +q w q y ) = ±1 (i.e, β = ± π 2 ), Equation (130) reduces to where the double-sign in same order. Note that when β = ± π 2 , the Euler angles suffer from the gimbal lock as described in Section IV-A2.c, and thus we only have one degree of freedom for the remaining angles, α and γ . Therefore, the recovered Euler angles have many solutions as where the double-sign in same order. Equation (131) and (133) denote the conversion from a unit quaternion to Euler angles, the arrow 16 ⃝ in Figure 1b.

g: CONVERSION BETWEEN EULER ANGLES AND AXIS-ANGLE
Given Euler angles α, β, and γ for the x, y, and z axes, we can convert them to a unit quaternion using Equation (130), and VOLUME 11, 2023 again convert the unit quaternion to a rotation axis-angle using Equation (121) as where and n = 1 − q 2 w . If n = 0 (i.e.,q w = 1), the rotation angle is zero, and the rotation axis is an arbitrary unit vector.
Equation (134) corresponds to the conversion from Euler angles to a rotation axis-angle, the arrow 17 ⃝ in Figure 1b where the arrow is depicted with a dotted line because the conversion is indirectly calculated via a unit quaternion.
Inversely, given a rotation axisv = [v x , v y , v z ] ⊤ and an angle θ, we can convert them to a unit quaternion using Equation (113), and again convert the unit quaternion to Euler angles α, β, and γ for the x, y, and z axes using Equation (131) if where For the special case of v y s θ + v z v x d θ = ±1, we have many solutions for the Euler angles from Equation (133) as Equation (135) and (136) correspond to the conversion from a rotation axis-angle to Euler angles, the arrow 18 ⃝ in Figure 1b where the arrow is dotted because the conversion is indirect via a unit quaternion.
The conversions between various rotation representations in a three dimensional space are summarized in Table 5.

V. DISCUSSION
In this section, we discuss about the advantages and disadvantages of different rotation representations by comparing their performance with time and space complexity, and think about which representation is a better choice in various situations. We also review two important concepts in rotations, ambiguity and singularity, and discuss about a generalization of rotations, and rigid body motions.
A. PERFORMANCE COMPARISON 1) MEMORY USAGE Table 6 compares the memory usage between different rotation representations. It is straightforward to count how many float variables are needed for each of representations. However, in case of the rotation axis-angle, we can reduce it to a three dimensional vector by normalizing the rotation axis to a unit vector and multiplying it by the rotation angle as in Equation (73). One may use a similar trick for the unit quaternion because only three components are independent. However, it costs a computational expense when recovering the fourth element.
As a result, a rotation angle and Euler angles are minimal representations for 2D and 3D rotations, respectively. A rotation matrix contains redundant information, while a unit complex number, a rotation axis-angle and a unit quaternion need one more storage than the degree of freedom. Table 7 summarizes the number of operations required for composing two rotations.

2) COMPOSING TWO ROTATIONS
For 2D rotations, a rotation angle is cheapest because it only needs just 1 addition of two angles. The multiplication of two 2 × 2 matrices in Equation (9) requires 2 multiplications and 1 addition for each of 4 elements. The multiplication of two unit complex numbers in Equation (55) and (20) involves 4 multiplications and 2 additions. Here, we ignore the postprocessing for orthonormalizing the rotation matrix using the Gram-Schmidt process and normalizing the unit complex number after rotation composition.
For 3D rotations, on the other hand, the multiplication of two 3 × 3 matrices requires 3 multiplications and 2 additions for each of 9 elements, while the multiplication of two unit quaternions in Equation (120) and (95) involves 4 multiplications and 3 additions for each of 4 components. Again, we ignore the post-processing for orthonormalizing the rotation matrix and normalizing the unit quaternion after rotation composition.
There is no direct method composing Euler angles or axisangles, and so we need to detour through a unit quaternion. For Euler angles, we first convert two sets of Euler angles to two unit quaternions from Equation (130), which requires 6 trigonometric function calls, 10 multiplications and 2 additions for each of two sets of Euler angles. After composing two unit quaternions, we need to convert the result back to Euler angles from Equation (131) which involves 15 multiplications, 7 additions and 3 function calls for the general case. Therefore, 35 multiplications, 11 additions, 15 function calls are required in addition to those for composing two unit quaternions.
For rotation axis-angles, we first convert two axis-angles to two unit quaternions from Equation (113) which requires 1 division for the half angle, 2 trigonometric function calls and 3 multiplications for each of two rotation axis-angles. Then, we compose two unit quaternions, and convert it back to a rotation axis-angle from Equation (121) which requires 2 multiplication, 1 addition, 3 divisions, 1 square root function call and 1 atan2 function call. Therefore, 13 multiplications, 1 additions, 6 function calls are required in addition to those for composing two unit quaternions. For more details in counting the number of operations, please refer to [20].
As a result, for rotation composition in a three dimensional space Euler angles are the most expensive representation, while unit quaternions are the cheapest. Remember that a unit quaternion only requires one more storage than the degree of freedom. However, it is much efficient when composing rotations, which is necessary for calculating the pose of the end effector of a manipulator or chaining the trajectory of mobile robots. That is why unit quaternions are widely used for 3D rotations. Table 8 compares the operation counts for rotating a vector or rotating many vectors at once.

3) ROTATING A VECTOR
For 2D rotations, both a rotation matrix and a unit complex number require the same operations to rotate a vector, which are 4 multiplications and 2 additions from Equation (3) and (45). A rotation angle needs additional 2 trigonometric function calls to convert to a rotation matrix using Equation (4) or to a unit complex number using Equation (44). Thus, in total 4 multiplications, 2 additions and 2 function calls are required to rotate a vector using a rotation angle.
For rotating n vectors at once in a two dimensional space, a rotation matrix and a unit complex number repeat the same process n times, while a rotation angle is better to be converted to a rotation matrix or a unit complex number before rotating n vectors, which takes additional 2 trigonometric function calls.
For 3D rotations, on the other hand, a rotation matrix requires 3 multiplications and 2 additions for each of 3 elements from Equation (70). Meanwhile, a rotation axis-angle needs 18 multiplications, 12 additions and 2 trigonometric function call from Equation (69). Finally, a unit quaternion requires 24 multiplications and 17 additions from Equation (114) and (95). Here, we use the information that p and p ′ are pure quaternions, having the scalar part to be zero. However, this can be further reduced to 15 multiplications and 15 additions by using Equation (117). For Euler angles we need to convert them to a rotation matrix using Equation (59) before rotating a vector, which requires additional 13 multiplications, 4 additions and 6 trigonometric function calls.
Note that the rotation matrix is the fastest for rotating a vector in a three dimensional space. Therefore, for scalability it is better to convert a rotation axis-angle and a unit quaternion to rotation matrices before rotating many vectors at once. Converting a rotation axis-angle to a rotation matrix requires 12 multiplications, 13 additions and 2 trigonometric function calls from Equation (71), while converting a unit quaternion to a rotation matrix involves 12 multiplications and 12 additions in Equation (123).
As a result, a rotation matrix and a unit complex number are the fastest to rotate a vector in a two dimensional space, while a rotation matrix is the fastest to rotate a vector in a three dimensional space. In particular, a rotation matrix is a good choice to rotate many vectors at once.

B. WHAT TO CHOOSE
There is no rule of thumb to choose the right rotation representation. However, we can judge which representations are preferred in different situations based on the advantages and disadvantages we have discussed so far. VOLUME 11, 2023 For 2D rotations, a rotation angle is the most efficient in storing and composing, and thus it is preferred when we need to store many rotations in the system and the rotation composition is the dominant operation such as there are many links in a manipulator or the trajectory of a mobile robot is too long. A rotation matrix is preferred in the opposite situation where only a few rotations are stored, and many points need to be rotated with the same rotation matrix. Otherwise, a unit complex number is a balanced representation from the perspective of time and space complexity.
For 3D rotations, on the other hand, a rotation matrix is preferred when not so many rotations need to be stored. Otherwise, it is preferred as a temporary representation for rotating vectors. Euler angles are preferred when a human operator is in the loop for saving, editing, monitoring rotations because they are intuitive and easy to interpret. A rotation axis-angle is preferred when the numerical optimization is critical for the system because its infinitesimal operations are well defined. Otherwise, a unit quaternion is a good choice because it does not suffer from singularity and is balanced in terms of time and space complexity. Moreover, when smooth interpolation is necessary such as in computer graphics, a unit quaternion is preferred because its spherical linear interpolation (SLERP) is well defined.

C. AMBIGUITY AND SINGULARITY
When dealing with rotations and orientations, two things should be kept in mind, ambiguity and singularity.
Ambiguity means that different rotations produce the same orientation. One typical reason for this is that rotation is a periodic motion. In other words, a rotation angle θ and θ ± 2nπ, where n is a natural number, result in the same orientation. This can be avoided by limiting rotation angles in the interval of [0, 2π) or (−π, π]. Another example is the sign ambiguity of unit quaternions, which is mentioned in Equation (114). It means that two unit quaternionsq and −q produce the same rotation, which can be avoided by setting the scalar parts of unit quaternions being non-negative. Note that the sign ambiguity is a source of potential problem when averaging rotations using unit quaternions.
Singularity, on the other hand, means that some rotations are numerically unstable. The gimbal lock is the typical example of singularity. As mentioned in Section IV-A2.c, in special cases of Euler angles and roll-pitch-yaw angles, one degree of freedom is lost, and the system is locked in a degenerate two-dimensional space. Singularity is often confused with ambiguity because for example in Equation (62) different combinations of α and γ produce the same orientation as long as α+γ is constant, i.e. multiple solutions for one orientation. However, singularity is different from ambiguity in that it cannot be avoided by limiting ranges, and more importantly when finding an optimal solution for a specific orientation, the iteration does not converge near singularity.

D. GENERALIZATION AND RIGID BODY MOTIONS
Another thing to mention about rotations is that rotations can also be considered as a composition of two reflections [21].
Moreover, there is a generalization of complex numbers and quaternions called Clifford algebras [22], and so can provide a unifying framework. For more information on Clifford algebras, refer to [23].
In this tutorial we have only focused on rotations, but to describe full rigid body motions, we need another motion component, translation. There are many representations for rigid body motions such as transformation matrices, dual quaternions, and twists. A transformation matrix combines a rotation matrix and a translation vector, which transforms homogeneous vectors. Dual quaternions consist of two quaternions which are for rotation and translation, respectively. A 6-vector twist represents the linear and angular velocity of a rigid body. For more information, refer to [12].

VI. CONCLUSION
In this tutorial, we learned rotation representations which are widely used for rigid body motions in industry and academia. We first learned rotation angles, 2 × 2 rotation matrices and unit complex numbers for a two dimensional space, and extended them to Euler angles, rotation axis-angles, 3 × 3 rotation matrices, and unit quaternions for a three dimensional space.
For the reader's convenience usage, the definitions and properties of mathematical entities used for representing rotations and the conversions between different rotation representations are summarized in tables. We hope this tutorial useful for engineers and scientists who are not familiar with rigid body motions, particularly with rotations.
When implementing the conversions between different rotation representations, numerical stability should be taken care of by avoiding dividing a very small number or taking the square root of a very small number [24].