Fact-checked by Grok 2 weeks ago

Rotation matrix

A rotation matrix is a square that represents a linear corresponding to a of vectors in around a fixed and , preserving the length and orientation of vectors while changing their direction by a specified . In two dimensions, it takes the form \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}, where \theta is the of counterclockwise , and applying this to a vector rotates it by \theta without altering its . In three dimensions, a rotation matrix is a 3×3 with 1, generally derived from : R(\hat{n}, \theta) = \cos\theta \, I + (1 - \cos\theta) \hat{n} \hat{n}^T + \sin\theta \, [\hat{n}]_\times, where \hat{n} is the unit axis vector, \theta is the rotation angle, I is the , and [\hat{n}]_\times is the cross-product matrix. Key properties include (R^T R = I), unit determinant (distinguishing rotations from reflections), and the fact that matrix multiplication corresponds to composition of rotations, though rotations about different axes do not commute. These matrices form the special SO(3), ensuring they map the unit sphere to itself and preserve angles and distances. Rotation matrices are fundamental in fields such as for rendering oriented objects, for coordinate frame transformations and manipulator , and physics for describing motions. They enable efficient computation of orientations in 3D space, though alternatives like quaternions are sometimes preferred to avoid singularities like .

Two-dimensional case

Matrix form

In two dimensions, a counterclockwise of a point about the origin by an angle \theta is represented by the R(\theta) = \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}. This arises from the trigonometric formulas applied to polar coordinates. Consider a point (x, y) with polar representation x = r \cos \phi and y = r \sin \phi, where r = \sqrt{x^2 + y^2} is the radius and \phi is the initial angle from the positive x-axis. After by \theta, the new coordinates are x' = r \cos(\phi + \theta) and y' = r \sin(\phi + \theta). Substituting the angle identities \cos(\phi + \theta) = \cos \phi \cos \theta - \sin \phi \sin \theta and \sin(\phi + \theta) = \sin \phi \cos \theta + \cos \phi \sin \theta yields x' = x \cos \theta - y \sin \theta and y' = x \sin \theta + y \cos \theta. In form, this is \begin{pmatrix} x' \\ y' \end{pmatrix} = R(\theta) \begin{pmatrix} x \\ y \end{pmatrix}. The rotation matrix preserves distances and because it is orthogonal, satisfying R(\theta)^T R(\theta) = I. To see this explicitly via the , note that for any vectors \mathbf{u} and \mathbf{v}, the transforms as (R\mathbf{u}) \cdot (R\mathbf{v}) = \mathbf{u}^T R^T R \mathbf{v} = \mathbf{u}^T \mathbf{v}, since R^T R = I. Preservation of the implies that lengths \|\mathbf{u}\| = \sqrt{\mathbf{u} \cdot \mathbf{u}} are unchanged and between vectors remain the same, as the cosine of the angle is the normalized . For example, a 90° counterclockwise (\theta = \pi/2) gives \cos(\pi/2) = 0 and \sin(\pi/2) = 1, so R(\pi/2) = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}, which maps (1, 0) to (0, 1) and (0, 1) to (-1, 0).

Geometric interpretation

A two-dimensional represents a linear that rotates points and vectors counterclockwise around the by an \theta, preserving their distances from the origin and angles between them, without introducing scaling or shearing effects. This geometric action can be visualized on the , where the matrix maps every point on the circle to another point on the same circle, effectively rotating the entire rigidly around the origin. The standard convention defines positive \theta as counterclockwise rotation, aligning with the right-hand rule in the plane; for instance, applying the matrix to the basis vector (1, 0) yields (\cos \theta, \sin \theta), which traces the unit circle as \theta varies. To achieve clockwise rotation, one can use a negative angle -\theta in the matrix or apply the transpose of the rotation matrix, which corresponds to the inverse transformation and rotates by -\theta. As a concrete example, rotating the vector (1, 0) by $45^\circ (or \pi/4 radians) counterclockwise results in the new position \left( \frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2} \right), demonstrating the matrix's role in redirecting vectors along circular paths without altering their magnitude.

Relation to complex numbers

In two dimensions, a rotation of a point about the origin by an angle \theta counterclockwise can be represented as multiplication by the complex exponential e^{i\theta} = \cos \theta + i \sin \theta, where the point is identified with a complex number z = x + i y corresponding to the vector (x, y). This operation rotates the complex plane by \theta radians, preserving distances from the origin since |e^{i\theta}| = 1. This complex multiplication is equivalent to applying the standard 2D rotation matrix, as the real and imaginary parts of e^{i\theta} z align with the matrix-vector product. Specifically, multiplying z by \cos \theta + i \sin \theta yields (\cos \theta \, x - \sin \theta \, y) + i (\sin \theta \, x + \cos \theta \, y), which matches the action of the matrix \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix} on the vector \begin{pmatrix} x \\ y \end{pmatrix}. The correspondence arises by representing the \cos \theta + i \sin \theta as the matrix \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}, where the real part forms the diagonal and the imaginary part the off-diagonal with appropriate signs. For example, a 90° rotation (\theta = \pi/2) corresponds to multiplication by i = e^{i\pi/2}, which transforms z = 1 (the point (1, 0)) to i (the point (0, 1)), equivalent to the matrix \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}. Compositions of such s are handled efficiently via , which states that (e^{i\theta})^n = e^{i n \theta} for integer n, allowing successive rotations by \theta to be computed as a single rotation by n\theta. This multiplicative structure in the complex numbers mirrors the group operation of for rotations.

Three-dimensional case

Rotations about fixed axes

In , rotations about fixed axes refer to transformations that rotate points around one of the principal coordinate axes—the x-axis, y-axis, or z-axis—by an angle θ, leaving the other two axes unchanged. These rotations extend the two-dimensional case by applying a rotation in the to the fixed axis while preserving coordinates along that axis. The convention for positive rotation direction follows the : point the thumb of the right hand along the axis of , and the fingers curl in the direction of positive θ, which corresponds to a counterclockwise when viewed looking toward the origin along the axis. To derive the rotation matrix about the x-axis, consider that the x-coordinate remains fixed, while the y and z coordinates undergo a in the yz-plane: R_x(\theta) = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{pmatrix}. This matrix rotates a point (x, y, z) to (x, y \cos \theta - z \sin \theta, y \sin \theta + z \cos \theta). Similarly, for the y-axis, the y-coordinate is fixed, and rotation occurs in the xz-plane: R_y(\theta) = \begin{pmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{pmatrix}, yielding (x \cos \theta + z \sin \theta, y, -x \sin \theta + z \cos \theta). For the z-axis, the z-coordinate is fixed, with rotation in the xy-plane: R_z(\theta) = \begin{pmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{pmatrix}, resulting in (x \cos \theta - y \sin \theta, x \sin \theta + y \cos \theta, z). As an example, a 90° rotation about the z-axis (θ = π/2) aligns the positive x-axis with the positive y-axis: applying R_z(\pi/2) to the vector (1, 0, 0) yields (0, 1, 0).

General rotation matrix

In three-dimensional , a general rotation matrix is a 3×3 real that describes an arbitrary proper , preserving lengths and orientations without reflections. It transforms a \mathbf{v} to a rotated \mathbf{v}' via \mathbf{v}' = R \mathbf{v}, where R maps the standard basis to a new orthonormal basis. A matrix R qualifies as a rotation matrix if it is orthogonal, satisfying R^T R = I, and has determinant \det(R) = 1, ensuring it represents a proper rotation rather than an improper one involving a reflection. These conditions guarantee that R preserves the inner product and right-handed coordinate system. The nine entries of R are not independent; orthogonality imposes six constraints (three from each column being unit vectors and three from columns being pairwise orthogonal), leaving three degrees of freedom corresponding to the dimensionality of the rotation space. The general rotation matrix can be parameterized using three independent angles, such as , which compose the rotation as a sequence of rotations about the coordinate axes. Equivalently, the entries of R are the direction cosines, defined as the cosines of the angles between the original axes and the rotated axes; specifically, the element R_{ij} is the cosine of the angle between the original i-th axis and the rotated j-th axis. This direction cosine matrix (DCM) formulation directly encodes the relative orientation of two coordinate frames. A foundational general form for such matrices was introduced by Olinde Rodrigues in 1840, providing an explicit expression for composing rotations that applies to arbitrary axes. Rotations about the fixed coordinate axes represent special cases of this general structure, where the axis aligns with a basis vector. For example, consider a rotation by $45^\circ (or \pi/4 radians) around the non-axis-aligned unit vector \mathbf{u} = \frac{1}{\sqrt{3}} (1, 1, 1). Using Rodrigues' formula, the resulting matrix is R = \begin{pmatrix} d & p & q \\ q & d & p \\ p & q & d \end{pmatrix}, where d = \frac{1 + \sqrt{2}}{3}, p = \frac{2 - \sqrt{2} - \sqrt{6}}{6}, and q = \frac{2 - \sqrt{2} + \sqrt{6}}{6}. This matrix satisfies R^T R = I and \det(R) = 1.

Axis-angle formulation

In three dimensions, any rotation can be uniquely specified (up to sign convention for the angle) by an axis of rotation given by a unit vector \mathbf{u} and a rotation angle \theta about that axis, where |\theta| \leq \pi. This axis-angle representation leads to the rotation matrix via Rodrigues' formula, which provides a closed-form expression for the matrix elements. Rodrigues' formula states that the rotation matrix R is R = I + (\sin \theta) K + (1 - \cos \theta) K^2, where I is the $3 \times 3 and K is the skew-symmetric cross-product matrix associated with the unit \mathbf{u} = (u_x, u_y, u_z)^T, K = \begin{pmatrix} 0 & -u_z & u_y \\ u_z & 0 & -u_x \\ -u_y & u_x & 0 \end{pmatrix}. This formula was originally derived by in 1840 as a geometric of the rotated into components parallel and perpendicular to the . An alternative algebraic derivation arises from the matrix exponential map R = \exp(\theta K), where the expansion \exp(X) = I + X + \frac{X^2}{2!} + \frac{X^3}{3!} + \cdots simplifies due to the properties of skew-symmetric K satisfying K^3 = -K and higher odd powers cycling accordingly, yielding exactly the Rodrigues expression after grouping terms. Given a rotation matrix R, the rotation angle \theta can be recovered from the trace via \theta = \cos^{-1} \left( \frac{\operatorname{tr}(R) - 1}{2} \right), which follows directly from substituting the into the trace and simplifying using properties of K. The \mathbf{u} is the unit eigenvector of R corresponding to the eigenvalue 1, since points on the remain fixed under , satisfying R \mathbf{u} = \mathbf{u}. As an illustrative example, consider a rotation by angle \theta around the unit \mathbf{u} = (0, 0, 1), corresponding to the z-axis. Here, K = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}, and substituting into yields R = \begin{pmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{pmatrix}, which embeds the standard two-dimensional rotation matrix in three dimensions while leaving the z-component unchanged.

Algebraic properties

Orthogonality and special orthogonal group

A rotation matrix R in n-dimensions satisfies the orthogonality condition R^T R = I, where R^T is the transpose of R and I is the , implying that R^{-1} = R^T. Such matrices form the O(n), which includes both proper rotations and improper rotations (reflections). The subset consisting of proper rotations, characterized by \det(R) = 1, constitutes the special orthogonal group SO(n). In two dimensions, the group SO(2) is isomorphic to the circle group U(1), the of s with modulus 1, reflecting the one-parameter family of rotations parameterized by an angle \theta. This isomorphism arises from mapping the rotation matrix \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix} to the complex number e^{i\theta}. In three dimensions, SO(3) possesses three degrees of freedom, corresponding to the independent parameters needed to specify an arbitrary rotation, such as the components of the rotation axis and the angle of rotation. Topologically, SO(3) is homeomorphic to the real projective space \mathbb{RP}^3, which captures the identification of antipodal points on the 3-sphere due to the double-covering by the unit quaternions. The condition \det(R) = 1 ensures that rotation matrices preserve , meaning they map right-handed coordinate systems to right-handed ones without reversal. To see this, recall that the of a linear transformation measures the signed volume scaling factor; a positive preserves the handedness of bases, while a negative one reverses it, as in reflections. For orthogonal matrices, \det(R^T R) = \det(I) = 1 implies [\det(R)]^2 = 1, so \det(R) = \pm 1. The choice +1 for SO(n) excludes orientation-reversing isometries, confirming that rotations maintain the original .

Trace and rotation angle

In three dimensions, the trace of a rotation matrix R is related to the rotation angle \theta by the formula \operatorname{tr}(R) = 1 + 2 \cos \theta. This relation arises because the eigenvalues of R are $1, e^{i\theta}, and e^{-i\theta}, with the trace being the sum of the eigenvalues: $1 + e^{i\theta} + e^{-i\theta} = 1 + 2 \cos \theta. In two dimensions, the rotation matrix has eigenvalues e^{i\theta} and e^{-i\theta}, yielding \operatorname{tr}(R) = 2 \cos \theta. The rotation angle \theta can be recovered from the trace using \theta = \arccos\left(\frac{\operatorname{tr}(R) - 1}{2}\right) in three dimensions or \theta = \arccos\left(\frac{\operatorname{tr}(R)}{2}\right) in two dimensions. Since the cosine function is even, \cos \theta = \cos (-\theta), the arccosine returns values in [0, \pi], resolving the ambiguity by selecting the nonnegative angle up to \pi radians, which uniquely represents rotations without duplication. For example, the identity matrix has trace 3 in three dimensions, corresponding to \theta = 0 since \arccos\left(\frac{3-1}{2}\right) = \arccos(1) = 0. A 180-degree rotation (\theta = \pi) has trace -1, as $1 + 2 \cos \pi = 1 + 2(-1) = -1.

Determinant and orientation

A rotation matrix R in n-dimensions is an orthogonal matrix with determinant \det(R) = 1, which ensures that it represents a proper rotation preserving the handedness or orientation of space. In contrast, orthogonal matrices with \det(R) = -1 correspond to improper transformations, such as reflections or rotoinversions, which reverse orientation by flipping the handedness from right to left or vice versa. This distinction arises because the determinant of an orthogonal matrix is always \pm 1, with the sign indicating whether the transformation maintains or reverses the geometric chirality. The determinant's role in orientation can be understood through its interpretation as the signed scaling factor for volumes under the linear transformation. For a rotation matrix, |\det(R)| = 1 means volumes are preserved without scaling, while the positive sign ensures that the of a basis (e.g., the standard right-handed basis) remains unchanged after . To see this, consider the formed by the columns of R; its signed volume equals \det(R) = 1, matching the unit volume of the and preserving the , where curling fingers along the basis vectors points the thumb in the positive direction. If \det(R) = -1, the signed volume becomes negative, inverting the to a left-hand , as if reflecting the space through a . This volume-based proof holds because rotations rigidly map space without distortion, and the sign tracks the consistency of the coordinate system's . In two dimensions, this is illustrated by comparing and matrices. A counterclockwise by \theta is given by R(\theta) = \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}, with \det(R(\theta)) = \cos^2 \theta + \sin^2 \theta = 1, preserving the counterclockwise ordering of basis vectors. A over a line at \theta/2 to the x-axis has the form S(\theta) = \begin{pmatrix} \cos \theta & \sin \theta \\ \sin \theta & -\cos \theta \end{pmatrix}, with \det(S(\theta)) = -\cos^2 \theta - \sin^2 \theta = -1, reversing the ordering (e.g., a square's traversal flips direction). For \theta = 0, R(0) = I (, det=1) preserves , while S(0) = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} reflects over the x-axis (det=-1), swapping y-coordinates and inverting . An instructive example of orientation reversal involves modifying a rotation matrix: starting from R(\theta), replacing the off-diagonal signs to mimic a "transposed" form yields \begin{pmatrix} \cos \theta & \sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}, but the proper reflection analogue \begin{pmatrix} \cos \theta & \sin \theta \\ \sin \theta & -\cos \theta \end{pmatrix} has det=-1, demonstrating how sign changes introduce the orientation flip absent in true transposes of rotations (which remain det=1).

Composition and multiplication

Matrix product as composition

The product of two rotation matrices corresponds to the composition of the two rotations they represent. In the standard convention using column vectors, where a vector \mathbf{v} is transformed as \mathbf{v}' = R \mathbf{v}, the combined rotation R that applies rotation R_1 first followed by R_2 is given by the matrix product R = R_2 R_1. This order ensures that the transformation sequence is correctly captured, as R \mathbf{v} = R_2 (R_1 \mathbf{v}). The set of rotation matrices forms the special orthogonal group SO(n), which is closed under ; thus, the product of any two rotation matrices is itself a matrix. This closure property guarantees that successive s remain within the group of proper orthogonal transformations, preserving lengths, angles, and orientation in \mathbb{R}^n. In two dimensions, the composition of rotations simplifies notably due to commutativity. The product of two rotation matrices by angles \theta_1 and \theta_2 yields a single rotation matrix by the sum \theta_1 + \theta_2, analogous to multiplication where s correspond to multiplication by e^{i\theta}. Specifically, if R(\theta_1) = \begin{pmatrix} \cos\theta_1 & -\sin\theta_1 \\ \sin\theta_1 & \cos\theta_1 \end{pmatrix} and R(\theta_2) = \begin{pmatrix} \cos\theta_2 & -\sin\theta_2 \\ \sin\theta_2 & \cos\theta_2 \end{pmatrix}, then R(\theta_1) R(\theta_2) = R(\theta_1 + \theta_2). For a concrete example in three dimensions, consider composing a 90° rotation about the x-axis followed by a 90° about the y-axis. The x-axis rotation matrix is R_x(90^\circ) = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{pmatrix}, and the y-axis rotation matrix is R_y(90^\circ) = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{pmatrix}. The combined matrix is R = R_y(90^\circ) R_x(90^\circ) = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & -1 \\ -1 & 0 & 0 \end{pmatrix}, which represents a single equivalent to the sequence.

Non-commutativity

Unlike or , the composition of rotation matrices is not commutative in general. That is, for two rotation matrices R_1 and R_2 in three dimensions, R_1 R_2 \neq R_2 R_1 unless the rotations share the same or satisfy specific conditions. This non-commutativity arises because rotations in \mathrm{SO}(3) form a , where the order of application alters the final orientation. An exception occurs in two dimensions, where \mathrm{SO}(2) is abelian, as rotations correspond to angle additions that commute. A illustration in three dimensions involves successive 90° rotations about the x-axis followed by the y-axis, versus the reverse order. Applying a 90° counterclockwise about the x-axis first transforms the y-axis to the z-axis and the z-axis to the negative y-axis; subsequent 90° about the (original) y-axis yields a final equivalent to a 120° about the axis (1,1,1)/\sqrt{3}. Reversing the order—90° about y first, then x—results in a different final , equivalent to a 120° about (1,1,-1)/\sqrt{3}. These distinct outcomes highlight how the sequence determines the composite . In the Lie algebra \mathfrak{so}(3) associated with \mathrm{SO}(3), non-commutativity is quantified by the Lie [A, B] = AB - BA, where A and B are skew-symmetric matrices representing rotations. This , which is itself skew-symmetric, captures the extent to which two generators fail to commute and underlies the non-abelian structure of the group. This property has practical implications in fields like , where the precise sequence of joint rotations must be controlled to achieve desired end-effector orientations; swapping orders can lead to significant positional errors.

Ambiguities in representation

Rotation matrices, while uniquely determining a rotation in three-dimensional space when properly interpreted, are subject to several representational ambiguities arising from conventions in their definition and application. One fundamental equivalence stems from the periodic nature of rotations: a rotation by 360° (or 2π radians) around any axis is identical to no rotation at all, meaning the identity matrix represents both 0° and 360° rotations. In the axis-angle formulation, this periodicity implies that angles θ and θ + 2πk (for integer k) yield the same matrix, though conventions often restrict θ to [0, 2π) to avoid redundancy. A related ambiguity occurs specifically for 180° rotations in three dimensions: rotating by 180° around an \mathbf{u} produces the same as rotating by 180° around the negative -\mathbf{u}, since the rotation matrix depends on \mathbf{u} \sin \theta and \mathbf{u} \mathbf{u}^T (1 - \cos \theta), and for \theta = 180^\circ = \pi, \sin \pi = 0 and \cos \pi = -1, making the expressions invariant under \mathbf{u} \to -\mathbf{u}. To resolve this, standard conventions limit the rotation to [0, π] and choose the direction accordingly, ensuring a unique representation except at this boundary case. Another source of ambiguity lies in the distinction between active and passive transformations. In an active transformation, the rotation matrix R directly rotates the physical object or in a fixed coordinate frame, such that the new position is R \mathbf{v}. Conversely, a passive transformation rotates the coordinate frame itself while keeping the object fixed, leading to components in the new frame given by R^{-1} \mathbf{v} = R^T \mathbf{v} (since rotation matrices are orthogonal). This duality means the same matrix R can represent an active by angle θ or a passive by -θ, as the passive case effectively uses the transpose, which corresponds to the . The choice of coordinate system handedness introduces further ambiguity in the sign convention for rotations. Right-handed systems, the standard in most mathematical and physical contexts, define positive rotations according to the , where the matrix for a counterclockwise rotation about the z-axis is \begin{pmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{pmatrix}. In left-handed systems, such as those sometimes used in , the positive rotation direction reverses, effectively negating the off-diagonal signs in the matrix to maintain consistency with the altered basis orientation. Thus, the same physical rotation may yield matrices that are transposes of each other depending on whether a right- or left-handed basis is employed. These ambiguities highlight the importance of specifying conventions: for instance, a rotation that appears as a counterclockwise turn in a right-handed, fixed-frame (passive) might correspond to a clockwise active transformation in a left-handed system, resulting in different numerical matrices for the identical geometric effect. Adopting consistent standards, such as right-handed bases and passive prevalent in and , mitigates such issues in applications.

Decompositions and parameterizations

Euler angles

Euler angles provide a parameterization of three-dimensional rotations using three angles that represent successive rotations about specific axes, typically fixed or body-fixed. This approach extends the two-dimensional rotation angle to three dimensions by composing three individual rotations, each about one of the coordinate axes. Common conventions include the Z-X-Z proper Euler angles and the X-Y-Z (or Z-Y-X) Tait-Bryan angles. In the Z-Y-X convention, the rotation matrix R is expressed as the product R = R_z(\phi) R_y(\theta) R_x(\psi), where \phi, \theta, and \psi are the yaw, pitch, and roll angles, respectively, and R_x, R_y, R_z are the elementary rotation matrices about the x-, y-, and z-axes. Similarly, for the Z-X-Z convention, R = R_z(\alpha) R_x(\beta) R_z(\gamma), with angles \alpha, \beta, and \gamma. The explicit form of the rotation matrix in the Z-Y-X is R = \begin{pmatrix} \cos\theta \cos\phi & -\cos\psi \sin\phi + \sin\psi \sin\theta \cos\phi & \sin\psi \sin\phi + \cos\psi \sin\theta \cos\phi \\ \cos\theta \sin\phi & \cos\psi \cos\phi + \sin\psi \sin\theta \sin\phi & -\sin\psi \cos\phi + \cos\psi \sin\theta \sin\phi \\ -\sin\theta & \sin\psi \cos\theta & \cos\psi \cos\theta \end{pmatrix}, where the angles are defined such that successive multiplications apply rotations in the body-fixed frame. For the Z-X-Z , the matrix expands to R = \begin{pmatrix} \cos\alpha \cos\gamma - \cos\beta \sin\alpha \sin\gamma & -\cos\alpha \sin\gamma - \cos\beta \cos\gamma \sin\alpha & \sin\alpha \sin\beta \\ \cos\gamma \sin\alpha + \cos\alpha \cos\beta \sin\gamma & \cos\alpha \cos\gamma - \cos\beta \sin\alpha \sin\gamma & -\cos\alpha \sin\beta \\ \sin\beta \sin\gamma & \cos\beta & \cos\beta \cos\gamma \end{pmatrix}. A key limitation of Euler angle parameterizations is gimbal lock, which occurs when the middle angle causes the rotation axes to align, such as θ = ±π/2 for the Z-Y-X or β = 0 or π for the Z-X-Z , resulting in a loss of one degree of freedom; the representation becomes singular, and multiple angle combinations can describe the same . For instance, the matrix R = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{pmatrix} corresponding to a 90° about the y-axis exhibits gimbal lock in the Z-Y-X at \theta = \pm \pi/2, where solutions include (\phi, \theta, \psi) = (0, \pi/2, 0) or (\pi/2, \pi/2, \pi/2), among others, illustrating the ambiguity at singularities.

Quaternion representation

A unit quaternion provides a parameterization of rotations in three-dimensional space, offering an alternative to the rotation matrix representation by embedding the special SO(3) into the unit in four dimensions. Specifically, any rotation by an angle θ around a unit axis \mathbf{u} = (u_x, u_y, u_z) is represented by the q = \cos(\theta/2) + \sin(\theta/2) (u_x \mathbf{i} + u_y \mathbf{j} + u_z \mathbf{k}), where the scalar part is \cos(\theta/2) and the vector part is \sin(\theta/2) \mathbf{u}. This form arises from the axis-angle representation, where the half-angle usage ensures the quaternion lies on the unit hypersphere. The mapping from unit quaternions to SO(3) is a double cover, meaning each corresponds to two antipodal quaternions q and -q, as both yield the same due to the even-powered trigonometric identities in the derivation. of corresponds to the of their : if q_1 and q_2 represent two , then q_2 q_1 (with in the order of application) represents their , preserving the group structure of SO(3) under this . This multiplicative property makes efficient for sequential , requiring fewer operations than . To obtain the corresponding 3×3 rotation matrix from a unit quaternion q = (q_0, q_1, q_2, q_3) with q_0^2 + q_1^2 + q_2^2 + q_3^2 = 1, the explicit formula is: \begin{pmatrix} 1 - 2q_2^2 - 2q_3^2 & 2q_1 q_2 - 2q_0 q_3 & 2q_1 q_3 + 2q_0 q_2 \\ 2q_1 q_2 + 2q_0 q_3 & 1 - 2q_1^2 - 2q_3^2 & 2q_2 q_3 - 2q_0 q_1 \\ 2q_1 q_3 - 2q_0 q_2 & 2q_2 q_3 + 2q_0 q_1 & 1 - 2q_1^2 - 2q_2^2 \end{pmatrix} This matrix is orthogonal with determinant 1, confirming it belongs to SO(3). For example, a 180° around the x-axis corresponds to \theta = 180^\circ, \mathbf{u} = (1, 0, 0), so q = (0, 1, 0, 0). Substituting into the formula yields \begin{pmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & -1 \end{pmatrix}, which correctly reflects the rotation by negating the y- and z-coordinates while preserving the x-coordinate.

Cayley transform and skew-symmetric matrices

The Cayley transform provides a parameterization of rotation matrices in terms of skew-symmetric matrices, offering a rational map from the Lie algebra \mathfrak{so}(n) to the special orthogonal group \mathrm{SO}(n). For a skew-symmetric matrix K \in \mathfrak{so}(n) (satisfying K^T = -K) such that I + K is invertible, the transform is defined as R = (I - K)(I + K)^{-1}, where I is the n \times n identity matrix; this yields R \in \mathrm{SO}(n), as R^T R = I and \det R = 1. The map is bijective onto the rotations for which -1 is not an eigenvalue of K, excluding certain rotations by \pi radians. In three dimensions, the K can be parameterized by a \omega \in \mathbb{R}^3 via the hat map, K = [\omega]_\times, where [\omega]_\times is the unique such that [\omega]_\times v = \omega \times v for all v \in \mathbb{R}^3. This \omega encodes the rotation axis \hat{u} = \omega / \|\omega\| (a ) and relates to the rotation angle \theta by \|\omega\| = \tan(\theta/2), with $0 \leq \theta < \pi. Thus, the three components of \omega serve as minimal parameters for \mathrm{SO}(3), providing a direct embedding of the rotation's geometry into Euclidean space without the need for four parameters as in quaternions. This parameterization avoids the singularities (gimbal lock) inherent in Euler angle representations, which occur when intermediate angles align with coordinate axes, though it introduces singularities for rotations exactly by \pi radians where I + K becomes singular. Additionally, the Cayley transform relates closely to the Rodrigues formula for rotations, as both express finite rotations quadratically in terms of skew-symmetric operators derived from the axis-angle pair, facilitating algebraic manipulations and derivations between the two. For small rotation angles \theta, the transform simplifies under approximation: since \tan(\theta/2) \approx \theta/2, it follows that K \approx (\theta/2) [\hat{u}]_\times, and substituting yields R \approx I - 2K \approx I - \theta [\hat{u}]_\times, aligning with the first-order infinitesimal rotation matrix (up to the sign convention for the axis direction).

Geometric and infinitesimal aspects

Geometry of rotations

In two dimensions, rotation matrices describe isometries of the Euclidean plane that fix the origin and map circles centered at the origin to themselves, effectively turning every point around this fixed point by a constant angle while preserving distances and oriented angles. This geometric action can be understood as a rigid transformation that rotates the entire plane counterclockwise (or clockwise for negative angles), with the origin serving as the unique fixed point under the rotation. For instance, points on a unit circle are permuted along the circle's circumference, maintaining their radial distance from the origin. Extending to three dimensions, rotation matrices represent isometries of Euclidean space that fix an entire line through the origin—the rotation axis—and rotate the plane perpendicular to this axis around it, again preserving distances and oriented angles. The origin remains fixed as part of this axis, but unlike in 2D, the entire axis consists of fixed points, while all other points trace circular paths in planes orthogonal to the axis. On the unit sphere, this action moves points along great circles lying in planes perpendicular to the rotation axis, with the latitude relative to the axis preserved but the longitude shifted uniformly. A concrete example illustrates this in 3D: consider a 90-degree rotation about the x-axis, which fixes all points along the x-axis (including the origin) and maps the equatorial great circle in the xy-plane to a meridional great circle in the xz-plane, effectively tilting the equator into a longitudinal slice through the poles. Such transformations highlight how rotations in higher dimensions generalize the circular motion of 2D while introducing an invariant axis that structures the geometry.

Infinitesimal rotations and Lie algebra

The Lie algebra of the special orthogonal group SO(n), denoted \mathfrak{so}(n), is the vector space of all n \times n real skew-symmetric matrices, i.e., matrices A satisfying A^T = -A, equipped with the Lie bracket [A, B] = AB - BA. This algebra captures the infinitesimal generators of rotations in n dimensions and forms the tangent space to SO(n) at the identity matrix. In two dimensions, \mathfrak{so}(2) is one-dimensional and spanned by the generator J = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}, which corresponds to counterclockwise rotations. Any element of \mathfrak{so}(2) is \theta J for \theta \in \mathbb{R}. In three dimensions, \mathfrak{so}(3) is three-dimensional, with a standard basis consisting of the skew-symmetric matrices that generate infinitesimal rotations about the coordinate axes: E_x = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{pmatrix}, \quad E_y = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 0 & 0 \\ -1 & 0 & 0 \end{pmatrix}, \quad E_z = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}. A general element \Omega \in \mathfrak{so}(3) can be expressed as \Omega = \omega_x E_x + \omega_y E_y + \omega_z E_z for \omega = (\omega_x, \omega_y, \omega_z)^T \in \mathbb{R}^3. This basis identifies \mathfrak{so}(3) with \mathbb{R}^3 via the hat map \hat{\cdot}: \mathbb{R}^3 \to \mathfrak{so}(3), where \hat{\omega} v = \omega \times v for v \in \mathbb{R}^3, yielding \hat{\omega} = \begin{pmatrix} 0 & -\omega_z & \omega_y \\ \omega_z & 0 & -\omega_x \\ -\omega_y & \omega_x & 0 \end{pmatrix}. Thus, E_x = \hat{e}_x, E_y = \hat{e}_y, and E_z = \hat{e}_z, where e_x, e_y, e_z are the standard basis vectors of \mathbb{R}^3. For a smooth curve R(t) of rotation matrices in SO(n) with R(0) fixed, the infinitesimal rotation at t=0 is captured by the derivative \dot{R}(0) = R(0) \Omega, where \Omega \in \mathfrak{so}(n) is skew-symmetric and encodes the instantaneous angular velocity in the body-fixed frame attached to R(0). In three dimensions, \Omega = \hat{\omega} for some angular velocity vector \omega \in \mathbb{R}^3, linking the Lie algebra directly to physical interpretations of rotational motion. The Cayley transform offers a means to approximate small finite rotations from elements of \mathfrak{so}(n).

Exponential map

The exponential map provides a homomorphism from the Lie algebra \mathfrak{so}(3) of skew-symmetric $3 \times 3 matrices to the special orthogonal group \mathrm{SO}(3) of rotation matrices, defined by R = \exp(\Omega) where \Omega \in \mathfrak{so}(3) and the exponential is the matrix exponential. This map generates all elements of \mathrm{SO}(3) from its Lie algebra, as the exponential is surjective: every rotation matrix R \in \mathrm{SO}(3) can be expressed as R = \exp(\Omega) for some skew-symmetric \Omega. For a rotation by angle \theta around a unit axis vector \mathbf{u}, the corresponding element in the Lie algebra is the scaled skew-symmetric matrix \Omega = \theta [\mathbf{u}], where [\mathbf{u}] denotes the skew-symmetric matrix associated with \mathbf{u}. The resulting rotation matrix is then R = \exp(\theta [\mathbf{u}]). This yields , a closed-form expression for the exponential: \exp(\theta K) = I + (\sin \theta) K + (1 - \cos \theta) K^2, where K = [\mathbf{u}] is the unit skew-symmetric matrix satisfying K^3 = -K and K^2 = -I + \mathbf{u} \mathbf{u}^T. The formula derives from the power series expansion of the matrix exponential, \exp(\theta K) = \sum_{k=0}^\infty \frac{(\theta K)^k}{k!}. Since the powers of K satisfy a cyclic relation (K^3 + K = 0), the series groups into terms resembling the Taylor expansions of \sin \theta and \cos \theta: the odd powers contribute to the \sin \theta coefficient, while even powers yield the \cos \theta terms. Alternatively, the derivation uses the eigenvalues of K, which are $0, i, -i; thus, \exp(\theta K) has eigenvalues $1, e^{i\theta}, e^{-i\theta}, confirming it is a rotation matrix with the specified angle and preserving orthogonality and determinant 1. As an example, consider rotation around the z-axis by angle \theta, generated by the infinitesimal rotation matrix J_z = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}. Then \exp(\theta J_z) = \begin{pmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{pmatrix}, which matches the standard 2D rotation embedded in 3D and follows directly from substituting into Rodrigues' formula.

Conversions and applications

From rotation matrix to axis-angle

To extract the axis-angle representation from a given 3D rotation matrix R \in \mathrm{SO}(3), the rotation angle \theta and unit axis \mathbf{u} can be determined using properties of the Rodriguez formula and the geometry of rotations. The process involves first computing the angle from the trace of R, then finding the axis as the eigenvector corresponding to eigenvalue 1 or via the skew-symmetric component of R. This reverses the construction of R from axis-angle parameters and is useful in robotics, computer graphics, and computer vision for decomposing orientations. The rotation angle \theta \in [0, \pi] is computed from the trace of R using the relation derived from the Rodriguez formula: \cos \theta = \frac{\trace(R) - 1}{2}, so \theta = \arccos\left( \frac{\trace(R) - 1}{2} \right). This holds because the diagonal elements of R contribute $1 + 2 \cos \theta to the trace. Special cases require careful handling: if \trace(R) = 3, then \theta = 0 and R is the , making the axis \mathbf{u} arbitrary (any unit vector suffices, as the rotation is trivial); if \trace(R) = -1, then \theta = \pi, and the axis is determined up to sign (since rotation by \pi around \mathbf{u} is equivalent to rotation by \pi around -\mathbf{u}). For numerical stability, especially when \theta is small (i.e., \trace(R) near 3), direct use of \arccos should be avoided due to loss of precision from floating-point errors near \cos \theta = 1; instead, compute \theta \approx \sqrt{2(1 - \cos \theta)} using a Taylor approximation or equivalent stabilized methods. Once \theta is known and \sin \theta \neq 0, the unit axis \mathbf{u} can be found by solving for the eigenvector of R corresponding to eigenvalue 1, since rotation leaves the axis unchanged: R \mathbf{u} = \mathbf{u}. This can be done via standard eigensolvers, though in 3D it reduces to solving a characteristic equation. An alternative, often more efficient approach exploits the skew-symmetric part of R: let \hat{\omega} = \frac{R - R^T}{2 \sin \theta}, where \hat{\omega} is the skew-symmetric matrix corresponding to the axis-angle vector \boldsymbol{\omega} = \theta \mathbf{u}. The axis is then the unit vector extracted from \hat{\omega} (denoted \vee \hat{\omega} = \boldsymbol{\omega}, so \mathbf{u} = \boldsymbol{\omega} / \theta). Explicitly, \mathbf{u} = \frac{1}{\sqrt{(3 - \trace(R))(1 + \trace(R))}} \begin{pmatrix} R_{32} - R_{23} \\ R_{13} - R_{31} \\ R_{21} - R_{12} \end{pmatrix}, derived from the off-diagonal elements. For the special case \theta = \pi (where \sin \theta = 0), the skew-symmetric method fails due to division by zero; instead, use the eigenvector approach or decompose the symmetric part S = R + R^T - ( \trace(R) - 1 ) I, where \mathbf{u}_j \mathbf{u}_k = S_{jk} / (3 - \trace(R)) for the outer product \mathbf{u} \mathbf{u}^T. Near \theta = 0 or \pi, the axis becomes ill-conditioned due to sensitivity to perturbations in R, requiring regularization or approximation (e.g., \boldsymbol{\omega} \approx \vee(R - I) for small \theta). As an illustrative example, consider the rotation matrix for a 90° (\theta = \pi/2) rotation around the z-axis: R = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}. First, \trace(R) = 1, so \cos \theta = (1 - 1)/2 = 0 and \theta = \arccos(0) = \pi/2. Then, \sin \theta = 1, and R - R^T = \begin{pmatrix} 0 & -2 & 0 \\ 2 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}, so \frac{R - R^T}{2 \sin \theta} = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix} = \hat{\mathbf{u}}, with \vee \hat{\mathbf{u}} = (0, 0, 1)^\top, yielding \mathbf{u} = (0, 0, 1)^\top. For the special case \theta = \pi around the x-axis, R = \begin{pmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & -1 \end{pmatrix}, \trace(R) = -1, \theta = \pi. Here R is symmetric, so use the eigenvector: solving \det(R - I) = 0 gives eigenvalue 1 with \mathbf{u} = (1, 0, 0)^\top. These steps confirm the decomposition matches the original parameters.

Polar decomposition

The polar decomposition theorem states that any invertible square matrix M \in \mathbb{R}^{n \times n} can be uniquely factored as M = R U, where R is a (orthogonal with positive determinant) and U is a symmetric positive definite matrix representing the stretch or deformation component. This factorization isolates the rigid rotational part from the non-rigid stretching, making it useful in applications like computer graphics and continuum mechanics where transformations need to be separated into pure rotation and distortion. To compute the decomposition, first form the symmetric matrix C = M^T M, then find its unique positive definite square root U = \sqrt{C}, and finally obtain the rotation as R = M U^{-1} or equivalently R = M (M^T M)^{-1/2}. The square root can be computed via eigenvalue decomposition of C, taking the positive roots of the eigenvalues and reconstructing the matrix. This approach ensures numerical stability for well-conditioned matrices. The decomposition is unique for invertible matrices, with R being the orthogonal matrix closest to M in the Frobenius norm. It relates directly to the singular value decomposition (SVD) of M = V \Sigma W^T, where the rotation is R = V W^T and the stretch is U = W \Sigma W^T, the symmetric positive definite matrix formed by conjugating the singular values. While SVD provides the factors, polar decomposition offers a more direct extraction of the rotation without requiring full singular vector computation in some iterative methods. As an example, consider a simple shear-scaled matrix such as M = \begin{pmatrix} 1 & k \\ 0 & 1 \end{pmatrix} for k > 0, which distorts a into a . The polar decomposition separates this into a counterclockwise R by an \theta = \frac{1}{2} \arctan(k) and a symmetric stretch U with eigenvalues \sqrt{1 + \frac{k^2}{4}} \pm \frac{k}{2}, capturing the elongation along the direction while preserving the rotational component.

Uniformly random rotation matrices

Uniformly random rotation matrices are elements of the special SO(n) distributed according to the , which is the unique invariant under left and right multiplication by group elements. This ensures that the sampling respects the group's geometry, providing a over the manifold of rotations in n dimensions. Such matrices are essential for simulations requiring unbiased random orientations, as the avoids biases toward particular rotation types. A standard method to generate Haar-distributed matrices in SO(n) involves the QR decomposition of a random matrix. Specifically, generate an n × n matrix Z with independent standard normal entries, compute its QR decomposition Z = QR where Q is orthogonal and R is upper triangular, then form Q' = Q Λ with Λ = diag(r_{jj} / |r_{jj}|) for j = 1 to n to ensure positive diagonals in R; the resulting Q' is uniformly distributed in SO(n) according to the . This approach leverages the invariance properties of the Gaussian ensemble under orthogonal transformations, guaranteeing uniformity. The Gram-Schmidt orthogonalization process inherent in QR decomposition further ensures the output lies on the before adjustment to SO(n). For the three-dimensional case SO(3), an efficient parameterization uses the axis-angle representation, where the rotation axis is sampled uniformly on the unit S² and the rotation θ is drawn from the interval [0, π] with (1/2) sin θ. This distribution arises from the volume element of the in or axis- coordinates, proportional to sin θ dθ dΩ, ensuring uniformity over the group. The corresponding rotation matrix can then be constructed using the from the sampled and . These sampling techniques find applications in simulations for and physics, where random rotations model isotropic orientations, such as in ray tracing or . In , uniform random rotation matrices enable for 3D models by applying unbiased rotations to training samples, improving robustness to orientation variations in tasks like object and segmentation.