GO-V.ORG
As seen in

Rotation matrix

In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation in Euclidean space. For example, using the convention below, the matrix R = \begin{bmatrix \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix \cdot rotates points in the plane counterclockwise through an angle about the origin of a two-dimensional Cartesian coordinate system. To perform the rotation on a plane point with standard coordinates , it should be written as a column vector, and multiplied by the matrix : R\mathbf{v = \begin{bmatrix \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix \begin{bmatrix x \\ y \end{bmatrix = x\begin{bmatrix \cos \theta \\... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation in Euclidean space. For example, using the convention below, the matrix R = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix}\cdot rotates points in the plane counterclockwise through an angle about the origin of a two-dimensional Cartesian coordinate system. To perform the rotation on a plane point with standard coordinates , it should be written as a column vector, and multiplied by the matrix : R\mathbf{v} = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = x\begin{bmatrix} \cos \theta \\ \sin \theta \end{bmatrix} + y\begin{bmatrix} -\sin \theta \\ \cos \theta \end{bmatrix} = \begin{bmatrix} x\cos\theta-y\sin\theta \\ x\sin\theta+y\cos\theta \end{bmatrix}. If and are the coordinates of the endpoint of a vector with the length r and the angle \phi with respect to the -axis, so that x = r \cos \phi and y = r \sin \phi , then the above equations become the trigonometric summation angle formulae: R\mathbf{v} = r\begin{bmatrix} \cos\phi\cos\theta-\sin\phi\sin\theta \\ \cos\phi\sin\theta+\sin\phi\cos\theta \end{bmatrix} = r\begin{bmatrix} \cos(\phi+\theta)\\ \sin(\phi+\theta) \end{bmatrix}. Indeed, these are the trigonometric summation angle formulae in matrix form. One way to understand this is to say we have a vector at an angle 30° from the -axis, and we wish to rotate that angle by a further 45°. We simply need to compute the vector endpoint coordinates at 75°. The examples in this article apply to active rotations of vectors counterclockwise in a right-handed coordinate system ( counterclockwise from ) by pre-multiplication (the rotation matrix applied on the left of the column vector to be rotated). If any one of these is changed (such as rotating axes instead of vectors, a passive transformation), then the inverse of the example matrix should be used, which coincides with its transpose. Since matrix multiplication has no effect on the zero vector (the coordinates of the origin), rotation matrices describe rotations about the origin. Rotation matrices provide an algebraic description of such rotations, and are used extensively for computations in geometry, physics, and computer graphics. In some literature, the term rotation is generalized to include improper rotations, characterized by orthogonal matrices with a determinant of −1 (instead of +1). An improper rotation combines a proper rotation with reflections (which invert orientation). In other cases, where reflections are not being considered, the label proper may be dropped. The latter convention is followed in this article. Rotation matrices are square matrices, with real entries. More specifically, they can be characterized as orthogonal matrices with determinant 1; that is, a square matrix is a rotation matrix if and only if and . The set of all orthogonal matrices of size with determinant +1 is a representation of a group known as the special orthogonal group , one example of which is the rotation group SO(3). The set of all orthogonal matrices of size with determinant +1 or −1 is a representation of the (general) orthogonal group . ==In two dimensions== In two dimensions, the standard rotation matrix has the following form: R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \\ \end{bmatrix}. This rotates column vectors by means of the following matrix multiplication, \begin{bmatrix} x' \\ y' \\ \end{bmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \\ \end{bmatrix}\begin{bmatrix} x \\ y \\ \end{bmatrix}. Thus, the new coordinates of a point after rotation are \begin{align} x' &= x \cos\theta - y \sin\theta\, \\ y' &= x \sin\theta + y \cos\theta\, \end{align}. \mathbf{\hat{x}} = \begin{bmatrix} 1 \\ 0 \\ \end{bmatrix} is rotated by an angle , its new coordinates are \begin{bmatrix} \cos\theta \\ \sin\theta \\ \end{bmatrix}, and when the vector (initially aligned with the y-axis of the coordinate system) \mathbf{\hat{y}} = \begin{bmatrix} 0 \\ 1 \\ \end{bmatrix} is rotated by an angle , its new coordinates are \begin{bmatrix} -\sin\theta \\ \cos\theta \\ \end{bmatrix}. R(\theta) . Thus the clockwise rotation matrix is found as (by replacing with and using the trigonometric symmetry of \sin(-\theta) = - \sin(\theta) and \cos( - \theta) = \cos(\theta) ) R(-\theta) = \begin{bmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \\ \end{bmatrix}. An alternative convention uses rotating axes (instead of rotating a vector), and the above matrices also represent a rotation of the axes clockwise through an angle . The two-dimensional case is the only non-trivial case where the rotation matrices group is commutative; it does not matter in which order rotations are multiply performed. For the 3-dimensional case, for example, a different order of multiple rotations gives a different result (e.g., rotating cell phones along the z-axis then the y-axis is not equal to rotating them along the y-axis then the z-axis.) ===Non-standard orientation of the coordinate system=== If a standard right-handed Cartesian coordinate system is used, with the to the right and the up, the rotation is counterclockwise. If a left-handed Cartesian coordinate system is used, with directed to the right but directed down, is clockwise. Such non-standard orientations are rarely used in mathematics but are common in 2D computer graphics, which often have the origin in the top left corner and the down the screen or page. See below for other alternative conventions which may change the sense of the rotation produced by a rotation matrix. ===Common 2D rotations=== Matrices \begin{bmatrix} 1 & 0 \\[3pt] 0 & 1 \\ \end{bmatrix}, \quad \begin{bmatrix} 0 & -1 \\[3pt] 1 & 0 \\ \end{bmatrix}, \quad \begin{bmatrix} -1 & 0 \\[3pt] 0 & -1 \\ \end{bmatrix}, \quad \begin{bmatrix} 0 & 1 \\[3pt] -1 & 0 \\ \end{bmatrix} are 2D rotation matrices corresponding to counter-clockwise rotations of respective angles of 0°, 90°, 180°, and 270°. ===Relationship with complex plane=== The matrices of the shape \begin{bmatrix} x & -y \\ y & x \end{bmatrix} form a ring, since their set is closed under addition and multiplication. Since \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}^2 \ =\ \begin{bmatrix} -1 & 0 \\ 0 & -1 \end{bmatrix} \ = -I (where I is the identity matrix), the map \begin{bmatrix} x & -y \\ y & x \end{bmatrix} = x\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} + y \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} \mapsto x+iy (where \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} corresponds to i ) is a ring isomorphism from this ring to the field of the complex numbers (incidentally, this shows that this ring is a field). Under this isomorphism, the rotation matrices \begin{bmatrix} \cos t & -\sin t \\ \sin t & \cos t \\ \end{bmatrix} = \cos t \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} + \sin t \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} correspond to the circle of the unit complex numbers, the complex numbers of modulus , since \cos t^2 + \sin t^2 = 1 . As a result, the following equality holds, e^{it} = \cos t + i\sin t = \cos t \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} + \sin t \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} = \begin{pmatrix}\cos t&-\sin t\\ \sin t&\cos t\end{pmatrix} where the first equality is Euler's formula, the matrix I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} corresponds to 1, and the matrix \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} corresponds to the imaginary unit i . If one identifies \mathbb R^2 with \mathbb C through the linear isomorphism (a,b)\mapsto a+ib , where (a,b) \in \mathbb R^2 and a+ib \in \mathbb C , the action of a matrix \begin{bmatrix} x & -y \\ y & x \end{bmatrix} on a vector (a,b) corresponds to multiplication on the complex number a+ib by . In other words, a vector rotation corresponds to multiplication on a complex number (corresponding to the vector being rotated) by a complex number of modulus (corresponding to the rotation matrix). ==In three dimensions== ===Basic 3D rotations=== A basic 3D rotation (also called elemental rotation) is a rotation about one of the axes of a coordinate system. The following three basic rotation matrices rotate vectors by an angle about the -, -, or -axis, in three dimensions, using the right-hand rule—which codifies their alternating signs. Notice that the right-hand rule only works when multiplying R \cdot \vec{x} . The same matrices can also represent a clockwise rotation of the axes keeping the vectors unchanged. \begin{alignat}{1} R_x(\theta) &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\[3pt] 0 & \sin \theta & \cos \theta \\[3pt] \end{bmatrix} \\[6pt] R_y(\theta) &= \begin{bmatrix} \cos \theta & 0 & \sin \theta \\[3pt] 0 & 1 & 0 \\[3pt] -\sin \theta & 0 & \cos \theta \\ \end{bmatrix} \\[6pt] R_z(\theta) &= \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\[3pt] \sin \theta & \cos \theta & 0 \\[3pt] 0 & 0 & 1 \\ \end{bmatrix} \end{alignat} For column vectors, each of these basic vector rotations appears counterclockwise when the axis about which they occur points toward the observer, the coordinate system is right-handed, and the angle is positive. , for instance, would rotate toward the a vector aligned with the , as can easily be checked by operating with on the vector : R_z(90^\circ) \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} \cos 90^\circ & -\sin 90^\circ & 0 \\ \sin 90^\circ & \quad\cos 90^\circ & 0\\ 0 & 0 & 1\\ \end{bmatrix} \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 & -1 & 0 \\ 1 & 0 & 0\\ 0 & 0 & 1\\ \end{bmatrix} \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \\ 0 \\ \end{bmatrix} This is similar to the rotation produced by the above-mentioned two-dimensional rotation matrix. See below for alternative conventions which may apparently or actually invert the sense of the rotation produced by these matrices. ===General 3D rotations=== Other 3D rotation matrices can be obtained from these three using matrix multiplication. For example, the product \begin{align} R = R_z(\alpha) \, R_y(\beta) \, R_x(\gamma) &= \overset\text{yaw} {\begin{bmatrix} \cos \alpha & -\sin \alpha & 0 \\ \sin \alpha & \cos \alpha & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}} \overset\text{pitch} {\begin{bmatrix} \cos \beta & 0 & \sin \beta \\ 0 & 1 & 0 \\ -\sin \beta & 0 & \cos \beta \\ \end{bmatrix}} \overset\text{roll} {\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \gamma & -\sin \gamma \\ 0 & \sin \gamma & \cos \gamma \\ \end{bmatrix}} \\ &= \begin{bmatrix} \cos\alpha\cos\beta & \cos\alpha\sin\beta\sin\gamma - \sin\alpha\cos\gamma & \cos\alpha\sin\beta\cos\gamma + \sin\alpha\sin\gamma \\ \sin\alpha\cos\beta & \sin\alpha\sin\beta\sin\gamma + \cos\alpha\cos\gamma & \sin\alpha\sin\beta\cos\gamma - \cos\alpha\sin\gamma \\ -\sin\beta & \cos\beta\sin\gamma & \cos\beta\cos\gamma \\ \end{bmatrix} \end{align} represents a rotation whose yaw, pitch, and roll angles are , and , respectively. More formally, it is an intrinsic rotation whose Tait–Bryan angles are , , , about axes , , , respectively. Similarly, the product \begin{align} \\ R = R_x(\alpha) \, R_y(\beta) \, R_z(\gamma) &= \overset\text{roll} {\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \alpha & -\sin \alpha \\ 0 & \sin \alpha & \cos \alpha \\ \end{bmatrix}} \overset\text{pitch} {\begin{bmatrix} \cos \beta & 0 & \sin \beta \\ 0 & 1 & 0 \\ -\sin \beta & 0 & \cos \beta \\ \end{bmatrix}} \overset\text{yaw} {\begin{bmatrix} \cos \gamma & -\sin \gamma & 0 \\ \sin \gamma & \cos \gamma & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}} \\ &= \begin{bmatrix} \cos\beta\cos\gamma & -\cos\beta\sin\gamma & \sin\beta \\ \cos\alpha\sin\gamma + \sin\alpha\sin\beta\cos\gamma & \cos\alpha\cos\gamma - \sin\alpha\sin\beta\sin\gamma & -\sin\alpha\cos\beta \\ \sin\alpha\sin\gamma - \cos\alpha\sin\beta\cos\gamma & \sin\alpha\cos\gamma + \cos\alpha\sin\beta\sin\gamma & \cos\alpha\cos\beta \\ \end{bmatrix} \end{align} represents an extrinsic rotation whose (improper) Euler angles are , , , about axes , , . These matrices produce the desired effect only if they are used to premultiply column vectors, and (since in general matrix multiplication is not commutative) only if they are applied in the specified order (see Ambiguities for more details). The order of rotation operations is from right to left; the matrix adjacent to the column vector is the first to be applied, and then the one to the left. ===Conversion from rotation matrix to axis–angle=== Every rotation in three dimensions is defined by its axis (a vector along this axis is unchanged by the rotation), and its angle — the amount of rotation about that axis (Euler rotation theorem). There are several methods to compute the axis and angle from a rotation matrix (see also axis–angle representation). Here, we only describe the method based on the computation of the eigenvectors and eigenvalues of the rotation matrix. It is also possible to use the trace of the rotation matrix. ====Determining the axis==== Given a rotation matrix , a vector parallel to the rotation axis must satisfy R\mathbf{u} = \mathbf{u}, since the rotation of around the rotation axis must result in . The equation above may be solved for which is unique up to a scalar factor unless is the identity matrix . Further, the equation may be rewritten R\mathbf{u} = I \mathbf{u} \implies \left(R - I\right) \mathbf{u} = 0, which shows that lies in the null space of . This means precisely that that is an eigenvector of corresponding to the eigenvalue . Every rotation matrix must have this eigenvalue, the other two eigenvalues being complex conjugates of each other. It follows that a general rotation matrix in three dimensions has, up to a multiplicative constant, only one real eigenvector. One way to determine the rotation axis is by showing that: \begin{align} 0 &= R^\mathsf{T} 0 + 0 \\ &= R^\mathsf{T}\left(R - I\right) \mathbf{u} + \left(R - I\right) \mathbf{u} \\ &= \left(R^\mathsf{T}R - R^\mathsf{T} + R - I\right) \mathbf{u} \\ &= \left(I - R^\mathsf{T} + R - I\right) \mathbf{u} \\ &= \left(R - R^\mathsf{T}\right) \mathbf{u} \end{align} Since is a skew-symmetric matrix, we can choose such that [\mathbf u]_{\times} = \left(R - R^\mathsf{T}\right). The matrix–vector product becomes a cross product of a vector with itself, ensuring that the result is zero: \left(R - R^\mathsf{T}\right) \mathbf{u} = [\mathbf u]_{\times} \mathbf{u} = \mathbf{u} \times \mathbf{u} = 0\, Therefore, if R = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \\ \end{bmatrix}, then \mathbf{u} = \begin{bmatrix} h-f \\ c-g \\ d-b \\ \end{bmatrix}. The magnitude of computed this way is , where is the angle of rotation. This does not work if is symmetric. Above, if is zero, then all subsequent steps are invalid. In this case, the angle of rotation is 0° or 180° and any nonzero column of is an eigenvector of with eigenvalue 1 because . ====Determining the angle==== To find the angle of a rotation, once the axis of the rotation is known, select a vector perpendicular to the axis. Then the angle of the rotation is the angle between and . A more direct method, however, is to simply calculate the trace: the sum of the diagonal elements of the rotation matrix. Care should be taken to select the right sign for the angle to match the chosen axis: \operatorname{tr} (R) = 1 + 2\cos\theta , from which follows that the angle's absolute value is |\theta| = \arccos\left(\frac{\operatorname{tr}(R) - 1}{2}\right). For the rotation axis \mathbf{n}=(n_1,n_2,n_3) , you can get the correct angle from \left\{\begin{matrix} \cos \theta&=&\dfrac{\operatorname{tr}(R) - 1}{2}\\ \sin \theta&=&-\dfrac{\operatorname{tr}(K_n R)}{2} \end{matrix}\right. where K_n=\begin{bmatrix} 0 & -n_3 & n_2\\ n_3 & 0 & -n_1\\ -n_2 & n_1 & 0\\ \end{bmatrix} ====Rotation matrix from axis and angle==== The matrix of a proper rotation by angle around the axis , a unit vector with , is given by: R = \begin{bmatrix} u_x^2 \left(1-\cos \theta\right) + \cos \theta & u_x u_y \left(1-\cos \theta\right) - u_z \sin \theta & u_x u_z \left(1-\cos \theta\right) + u_y \sin \theta \\ u_x u_y \left(1-\cos \theta\right) + u_z \sin \theta & u_y^2\left(1-\cos \theta\right) + \cos \theta & u_y u_z \left(1-\cos \theta\right) - u_x \sin \theta \\ u_x u_z \left(1-\cos \theta\right) - u_y \sin \theta & u_y u_z \left(1-\cos \theta\right) + u_x \sin \theta & u_z^2\left(1-\cos \theta\right) + \cos \theta \end{bmatrix}. A derivation of this matrix from first principles can be found in section 9.2 here. The basic idea to derive this matrix is dividing the problem into few known simple steps. First rotate the given axis and the point such that the axis lies in one of the coordinate planes ( , or ) Then rotate the given axis and the point such that the axis is aligned with one of the two coordinate axes for that particular coordinate plane ( , or ) Use one of the fundamental rotation matrices to rotate the point depending on the coordinate axis with which the rotation axis is aligned. Reverse rotate the axis-point pair such that it attains the final configuration as that was in step 2 (Undoing step 2) Reverse rotate the axis-point pair which was done in step 1 (undoing step 1) This can be written more concisely as R = (\cos\theta)\,I + (\sin\theta)\,[\mathbf u]_{\times} + (1-\cos\theta)\,(\mathbf{u}\otimes\mathbf{u}), where is the cross product matrix of ; the expression is the outer product, and is the identity matrix. Alternatively, the matrix entries are: R_{jk}=\begin{cases} \cos^2\frac{\theta}{2}+\sin^2\frac{\theta}{2}\left(2u_j^2-1\right), \quad &\text{if }j=k\\ 2u_ju_k\sin^2\frac{\theta}{2}-\varepsilon_{jkl}u_l\sin\theta, \quad &\text{if }j\neq k \end{cases} where is the Levi-Civita symbol with . This is a matrix form of Rodrigues' rotation formula, (or the equivalent, differently parametrized Euler–Rodrigues formula) with \mathbf{u}\otimes\mathbf{u} = \mathbf{u}\mathbf{u}^\mathsf{T} = \begin{bmatrix} u_x^2 & u_x u_y & u_x u_z \\[3pt] u_x u_y & u_y^2 & u_y u_z \\[3pt] u_x u_z & u_y u_z & u_z^2 \end{bmatrix},\qquad [\mathbf u]_{\times} = \begin{bmatrix} 0 & -u_z & u_y \\[3pt] u_z & 0 & -u_x \\[3pt] -u_y & u_x & 0 \end{bmatrix}. In \mathbb{R}^3 the rotation of a vector around the axis by an angle can be written as: R_{\mathbf{u}}(\theta)\mathbf{x}=\mathbf{u}(\mathbf{u}\cdot\mathbf{x})+\cos\left(\theta\right)(\mathbf{u}\times\mathbf{x})\times\mathbf{u}+\sin\left(\theta\right)(\mathbf{u}\times\mathbf{x}) or equivalently: R_{\mathbf{u}}(\theta)\mathbf{x}= \mathbf{x} \cos(\theta) + \mathbf{u}(\mathbf{x} \cdot \mathbf{u})(1- \cos(\theta)) - \mathbf{x} \times \mathbf{u} \sin{\theta} This can also be written in tensor notation as: (R_{\mathbf{u}}(\theta)\mathbf{x})_i = (R_{\mathbf{u}}(\theta))_{ij} {\mathbf{x}}_{j} \quad \text{with} \quad (R_{\mathbf{u}}(\theta))_{ij} = \delta_{ij}\cos(\theta) + \mathbf{u}_i\mathbf{u}_j (1- \cos(\theta)) - \sin{\theta} \varepsilon_{ijk} \mathbf{u}_{k} If the 3D space is right-handed and , this rotation will be counterclockwise when points towards the observer (Right-hand rule). Explicitly, with (\boldsymbol{\alpha}, \boldsymbol{\beta},\mathbf u) a right-handed orthonormal basis, R_{\mathbf{u}}(\theta)\boldsymbol{\alpha}= \cos\left(\theta\right) \boldsymbol{\alpha} + \sin\left(\theta\right) \boldsymbol{\beta}, \quad R_{\mathbf{u}}(\theta)\boldsymbol{\beta}= - \sin\left(\theta\right) \boldsymbol{\alpha} + \cos\left(\theta\right) \boldsymbol{\beta}, \quad R_{\mathbf{u}}(\theta)\mathbf{u}=\mathbf{u}. Note the striking merely apparent differences to the equivalent Lie-algebraic formulation below. R^\mathsf{T} = R^{-1} (The rotation is an orthogonal matrix) \det R = \pm 1 A rotation is termed proper if , and improper (or a roto-reflection) if . For even dimensions , the eigenvalues of a proper rotation occur as pairs of complex conjugates which are roots of unity: for , which is real only for . Therefore, there may be no vectors fixed by the rotation ( ), and thus no axis of rotation. Any fixed eigenvectors occur in pairs, and the axis of rotation is an even-dimensional subspace. For odd dimensions , a proper rotation will have an odd number of eigenvalues, with at least one and the axis of rotation will be an odd dimensional subspace. Proof: \begin{align} \det\left(R - I\right) &= \det\left(R^\mathsf{T}\right) \det\left(R - I\right) &= \det(I - R) Q = \begin{bmatrix} 0 & 1 \\ -1 & 0 \end{bmatrix} corresponds to a 90° planar rotation clockwise about the origin. The transpose of the matrix M = \begin{bmatrix} 0.936 & 0.352 \\ 0.352 & -0.936 \end{bmatrix} is its inverse, but since its determinant is −1, this is not a proper rotation matrix; it is a reflection across the line . The rotation matrix Q = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \frac{\sqrt{3}}{2} & \frac12 \\ 0 & -\frac12 & \frac{\sqrt{3}}{2} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos 30^\circ & \sin 30^\circ \\ 0 & -\sin 30^\circ & \cos 30^\circ \\ \end{bmatrix} corresponds to a −30° rotation around the -axis in three-dimensional space. The rotation matrix Q = \begin{bmatrix} 0.36 & 0.48 & -0.80 \\ -0.80 & 0.60 & 0.00 \\ 0.48 & 0.64 & 0.60 \end{bmatrix} corresponds to a rotation of approximately −74° around the axis in three-dimensional space. The permutation matrix P = \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix} is a rotation matrix, as is the matrix of any even permutation, and rotates through 120° about the axis . The matrix M = \begin{bmatrix} 3 & -4 & 1 \\ 5 & 3 & -7 \\ -9 & 2 & 6 \end{bmatrix} has determinant +1, but is not orthogonal (its transpose is not its inverse), so it is not a rotation matrix. The matrix M = \begin{bmatrix} 0.5 & -0.1 & 0.7 \\ 0.1 & 0.5 & -0.5 \\ -0.7 & 0.5 & 0.5 \\ -0.5 & -0.7 & -0.1 \end{bmatrix} is not square, and so cannot be a rotation matrix; yet yields a identity matrix (the columns are orthonormal). The matrix Q = -I = \begin{bmatrix} -1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix} describes an isoclinic rotation in four dimensions, a rotation through equal angles (180°) through two orthogonal planes. The rotation matrix Q = \begin{bmatrix} 0 & -1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{bmatrix} rotates vectors in the plane of the first two coordinate axes 90°, rotates vectors in the plane of the next two axes 180°, and leaves the last coordinate axis unmoved. d^2(O,P) = \| \mathbf{p} \|^2 = \sum_{r=1}^n p_r^2 which can be computed using the matrix multiplication \| \mathbf{p} \|^2 = \begin{bmatrix}p_1 \cdots p_n\end{bmatrix} \begin{bmatrix}p_1 \\ \vdots \\ p_n \end{bmatrix} = \mathbf{p}^\mathsf{T} \mathbf{p} . A geometric rotation transforms lines to lines, and preserves ratios of distances between points. From these properties it can be shown that a rotation is a linear transformation of the vectors, and thus can be written in matrix form, . The fact that a rotation preserves, not just ratios, but distances themselves, is stated as \mathbf{p}^\mathsf{T} \mathbf{p} = (Q \mathbf{p})^\mathsf{T} (Q \mathbf{p}) , or \begin{align} \mathbf{p}^\mathsf{T} I \mathbf{p}&{}= \left(\mathbf{p}^\mathsf{T} Q^\mathsf{T}\right) (Q \mathbf{p}) \\ &{}= \mathbf{p}^\mathsf{T} \left(Q^\mathsf{T} Q\right) \mathbf{p} . \end{align} Because this equation holds for all vectors, , one concludes that every rotation matrix, , satisfies the orthogonality condition, Q^\mathsf{T} Q = I . Rotations preserve handedness because they cannot change the ordering of the axes, which implies the special matrix condition, \det Q = +1 . Equally important, it can be shown that any matrix satisfying these two conditions acts as a rotation. \begin{align} \left(Q^\mathsf{T}\right)^\mathsf{T} \left(Q^\mathsf{T}\right) &= Q Q^\mathsf{T} = I\\ \det Q^\mathsf{T} &= \det Q = +1. \end{align} The product of two rotation matrices is a rotation matrix: \begin{align} \left(Q_1 Q_2\right)^\mathsf{T} \left(Q_1 Q_2\right) &= Q_2^\mathsf{T} \left(Q_1^\mathsf{T} Q_1\right) Q_2 = I \\ \det \left(Q_1 Q_2\right) &= \left(\det Q_1\right) \left(\det Q_2\right) = +1. \end{align} For , multiplication of rotation matrices is generally not commutative. \begin{align} Q_1 &= \begin{bmatrix}0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1\end{bmatrix} & Q_2 &= \begin{bmatrix}0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0\end{bmatrix} \\ Q_1 Q_2 &= \begin{bmatrix}0 & -1 & 0 \\ 0 & 0 & 1 \\ -1 & 0 & 0\end{bmatrix} & Q_2 Q_1 &= \begin{bmatrix}0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0\end{bmatrix}. \end{align} Noting that any identity matrix is a rotation matrix, and that matrix multiplication is associative, we may summarize all these properties by saying that the rotation matrices form a group, which for is non-abelian, called a special orthogonal group, and denoted by , , , or , the group of rotation matrices is isomorphic to the group of rotations in an space. This means that multiplication of rotation matrices corresponds to composition of rotations, applied in left-to-right order of their corresponding matrices. R(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \\ \end{bmatrix} represents a counterclockwise rotation of a vector by an angle , or a rotation of by the same angle but in the opposite direction (i.e. clockwise). Alibi and alias transformations are also known as active and passive transformations, respectively. Pre-multiplication or post-multiplication The same point can be represented either by a column vector or a row vector . Rotation matrices can either pre-multiply column vectors ( ), or post-multiply row vectors ( ). However, produces a rotation in the opposite direction with respect to . Throughout this article, rotations produced on column vectors are described by means of a pre-multiplication. To obtain exactly the same rotation (i.e. the same final coordinates of point ), the equivalent row vector must be post-multiplied by the transpose of (i.e. ). Right- or left-handed coordinates The matrix and the vector can be represented with respect to a right-handed or left-handed coordinate system. Throughout the article, we assumed a right-handed orientation, unless otherwise specified. Vectors or forms The vector space has a dual space of linear forms, and the matrix can act on either vectors or forms. Q = \begin{bmatrix} 0.36 & 0.48 & -0.80 \\ -0.80 & 0.60 & 0.00 \\ 0.48 & 0.64 & 0.60 \end{bmatrix} . If acts in a certain direction, , purely as a scaling by a factor , then we have Q \mathbf{v} = \lambda \mathbf{v}, so that \mathbf{0} = (\lambda I - Q) \mathbf{v} . Thus is a root of the characteristic polynomial for , \begin{align} 0 &{}= \det (\lambda I - Q) \\ &{}= \lambda^3 - \tfrac{39}{25} \lambda^2 + \tfrac{39}{25} \lambda - 1 \\ &{}= (\lambda-1) \left(\lambda^2 - \tfrac{14}{25} \lambda + 1\right). \end{align} Two features are noteworthy. First, one of the roots (or eigenvalues) is 1, which tells us that some direction is unaffected by the matrix. For rotations in three dimensions, this is the axis of the rotation (a concept that has no meaning in any other dimension). Second, the other two roots are a pair of complex conjugates, whose product is 1 (the constant term of the quadratic), and whose sum is (the negated linear term). This factorization is of interest for rotation matrices because the same thing occurs for all of them. (As special cases, for a null rotation the "complex conjugates" are both 1, and for a 180° rotation they are both −1.) Furthermore, a similar factorization holds for any rotation matrix. If the dimension, , is odd, there will be a "dangling" eigenvalue of 1; and for any dimension the rest of the polynomial factors into quadratic terms like the one here (with the two special cases noted). We are guaranteed that the characteristic polynomial will have degree and thus eigenvalues. And since a rotation matrix commutes with its transpose, it is a normal matrix, so can be diagonalized. We conclude that every rotation matrix, when expressed in a suitable coordinate system, partitions into independent rotations of two-dimensional subspaces, at most of them. The sum of the entries on the main diagonal of a matrix is called the trace; it does not change if we reorient the coordinate system, and always equals the sum of the eigenvalues. This has the convenient implication for and rotation matrices that the trace reveals the angle of rotation, , in the two-dimensional space (or subspace). For a matrix the trace is , and for a matrix it is . In the three-dimensional case, the subspace consists of all vectors perpendicular to the rotation axis (the invariant direction, with eigenvalue 1). Thus we can extract from any rotation matrix a rotation axis and an angle, and these completely determine the rotation. Q = \begin{bmatrix} a & -b \\ b & a \end{bmatrix} with . Therefore, we may set and , for some angle . To solve for it is not enough to look at alone or alone; we must consider both together to place the angle in the correct quadrant, using a two-argument arctangent function. Now consider the first column of a rotation matrix, \begin{bmatrix}a\\b\\c\end{bmatrix} . Although will probably not equal 1, but some value , we can use a slight variation of the previous computation to find a so-called Givens rotation that transforms the column to \begin{bmatrix}r\\0\\c\end{bmatrix} , zeroing . This acts on the subspace spanned by the - and -axes. We can then repeat the process for the -subspace to zero . Acting on the full matrix, these two rotations produce the schematic form Q_{xz}Q_{xy}Q = \begin{bmatrix}1&0&0\\0&\ast&\ast\\0&\ast&\ast\end{bmatrix} . Shifting attention to the second column, a Givens rotation of the -subspace can now zero the value. This brings the full matrix to the form Q_{yz}Q_{xz}Q_{xy}Q = \begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix} , which is an identity matrix. Thus we have decomposed as Q = Q_{xy}^{-1}Q_{xz}^{-1}Q_{yz}^{-1} . An rotation matrix will have , or \sum_{k=1}^{n-1} k = \frac{1}{2}n(n - 1) entries below the diagonal to zero. We can zero them by extending the same idea of stepping through the columns with a series of rotations in a fixed sequence of planes. We conclude that the set of rotation matrices, each of which has entries, can be parameterized by angles. In three dimensions this restates in matrix form an observation made by Euler, so mathematicians call the ordered sequence of three angles Euler angles. However, the situation is somewhat more complicated than we have so far indicated. Despite the small dimension, we actually have considerable freedom in the sequence of axis pairs we use; and we also have some freedom in the choice of angles. Thus we find many different conventions employed when three-dimensional rotations are parameterized for physics, or medicine, or chemistry, or other disciplines. When we include the option of world axes or body axes, 24 different sequences are possible. And while some disciplines call any sequence Euler angles, others give different names (Cardano, Tait–Bryan, roll-pitch-yaw) to different sequences. One reason for the large number of options is that, as noted previously, rotations in three dimensions (and higher) do not commute. If we reverse a given sequence of rotations, we get a different outcome. This also implies that we cannot compose two rotations by adding their corresponding angles. Thus Euler angles are not vectors, despite a similarity in appearance as a triplet of numbers. Q_{3 \times 3} = \begin{bmatrix} \cos \theta & -\sin \theta & {\color{CadetBlue}0} \\ \sin \theta & \cos \theta & {\color{CadetBlue}0} \\ {\color{CadetBlue}0} & {\color{CadetBlue}0} & {\color{CadetBlue}1} \end{bmatrix} suggests a rotation matrix, Q_{2 \times 2} = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix}, is embedded in the upper left corner: Q_{3 \times 3} = \left[ \begin{matrix} Q_{2 \times 2} & \mathbf{0} \\ \mathbf{0}^\mathsf{T} & 1 \end{matrix} \right]. This is no illusion; not just one, but many, copies of -dimensional rotations are found within -dimensional rotations, as subgroups. Each embedding leaves one direction fixed, which in the case of matrices is the rotation axis. For example, we have \begin{align} Q_{\mathbf{x}}(\theta) &= \begin{bmatrix} {\color{CadetBlue}1} & {\color{CadetBlue}0} & {\color{CadetBlue}0} \\ {\color{CadetBlue}0} & \cos \theta & -\sin \theta \\ {\color{CadetBlue}0} & \sin \theta & \cos \theta \end{bmatrix}, \\[8px] Q_{\mathbf{y}}(\theta) &= \begin{bmatrix} \cos \theta & {\color{CadetBlue}0} & \sin \theta \\ {\color{CadetBlue}0} & {\color{CadetBlue}1} & {\color{CadetBlue}0} \\ -\sin \theta & {\color{CadetBlue}0} & \cos \theta \end{bmatrix}, \\[8px] Q_{\mathbf{z}}(\theta) &= \begin{bmatrix} \cos \theta & -\sin \theta & {\color{CadetBlue}0} \\ \sin \theta & \cos \theta & {\color{CadetBlue}0} \\ {\color{CadetBlue}0} & {\color{CadetBlue}0} & {\color{CadetBlue}1} \end{bmatrix}, \end{align} fixing the -axis, the -axis, and the -axis, respectively. The rotation axis need not be a coordinate axis; if is a unit vector in the desired direction, then \begin{align} Q_\mathbf{u}(\theta) &= \begin{bmatrix} 0 & -z & y \\ z & 0 & -x \\ -y & x & 0 \end{bmatrix} \sin\theta + \left(I - \mathbf{u}\mathbf{u}^\mathsf{T}\right) \cos\theta + \mathbf{u}\mathbf{u}^\mathsf{T} \\[8px] &= \begin{bmatrix} \left(1 - x^2\right) c_\theta + x^2 & -z s_\theta - x y c_\theta + x y & y s_\theta - x z c_\theta + x z \\ z s_\theta - x y c_\theta + x y & \left(1 - y^2\right) c_\theta + y^2 & -x s_\theta - y z c_\theta + y z \\ -y s_\theta - x z c_\theta + x z & x s_\theta - y z c_\theta + y z & \left(1 - z^2\right) c_\theta + z^2 \end{bmatrix} \\[8px] &= \begin{bmatrix} x^2 (1 - c_\theta) + c_\theta & x y (1 - c_\theta) - z s_\theta & x z (1 - c_\theta) + y s_\theta \\ x y (1 - c_\theta) + z s_\theta & y^2 (1 - c_\theta) + c_\theta & y z (1 - c_\theta) - x s_\theta \\ x z (1 - c_\theta) - y s_\theta & y z (1 - c_\theta) + x s_\theta & z^2 (1 - c_\theta) + c_\theta \end{bmatrix}, \end{align} where , , is a rotation by angle leaving axis fixed. A direction in -dimensional space will be a unit magnitude vector, which we may consider a point on a generalized sphere, . Thus it is natural to describe the rotation group as combining and . A suitable formalism is the fiber bundle, SO(n) \hookrightarrow SO(n + 1) \to S^n , where for every direction in the base space, , the fiber over it in the total space, , is a copy of the fiber space, , namely the rotations that keep that direction fixed. Thus we can build an rotation matrix by starting with a matrix, aiming its fixed axis on (the ordinary sphere in three-dimensional space), aiming the resulting rotation on , and so on up through . A point on can be selected using numbers, so we again have numbers to describe any rotation matrix. In fact, we can view the sequential angle decomposition, discussed previously, as reversing this process. The composition of Givens rotations brings the first column (and row) to , so that the remainder of the matrix is a rotation matrix of dimension one less, embedded so as to leave fixed. A \mapsto (I+A)(I-A)^{-1} , which maps any skew-symmetric matrix to a rotation matrix. In fact, aside from the noted exceptions, we can produce any rotation matrix in this way. Although in practical applications we can hardly afford to ignore 180° rotations, the Cayley transform is still a potentially useful tool, giving a parameterization of most rotation matrices without trigonometric functions. In three dimensions, for example, we have \begin{align} &\begin{bmatrix} 0 & -z & y \\ z & 0 & -x \\ -y & x & 0 \end{bmatrix} \mapsto \\[3pt] \quad \frac{1}{1 + x^2 + y^2 + z^2} &\begin{bmatrix} 1 + x^2 - y^2 - z^2 & 2xy - 2z & 2y + 2xz \\ 2xy + 2z & 1 - x^2 + y^2 - z^2 & 2yz - 2x \\ 2xz - 2y & 2x + 2yz & 1 - x^2 - y^2 + z^2 \end{bmatrix} . \end{align} If we condense the skew entries into a vector, , then we produce a 90° rotation around the -axis for (1, 0, 0), around the -axis for (0, 1, 0), and around the -axis for (0, 0, 1). The 180° rotations are just out of reach; for, in the limit as , does approach a 180° rotation around the axis, and similarly for other directions. \begin{align} R(\theta) &{}= \begin{bmatrix} 1 & -\tan \frac{\theta}{2}\\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0\\ \sin \theta & 1 \end{bmatrix} \begin{bmatrix} 1 & -\tan \frac{\theta}{2}\\ 0 & 1 \end{bmatrix} \end{align} This is useful, for instance, in computer graphics, since shears can be implemented with fewer multiplication instructions than rotating a bitmap directly. On modern computers, this may not matter, but it can be relevant for very old or low-end microprocessors. A rotation can also be written as two shears and a squeeze mapping (an area preserving scaling) ( ): \begin{align} R(\theta) &{}= \begin{bmatrix} 1 & 0\\ \tan\theta & 1 \end{bmatrix} \begin{bmatrix} 1 & -\sin\theta\cos\theta\\ 0 & 1 \end{bmatrix} \begin{bmatrix} \cos\theta & 0\\ 0 & \frac{1}{\cos\theta} \end{bmatrix} \end{align} \mathfrak{so}(n) = \mathfrak{o}(n) = \left\{X \in M_n(\mathbb{R}) \mid X = -X^\mathsf{T} \right\}, and is the space of skew-symmetric matrices of dimension , see classical group, where is the Lie algebra of , the orthogonal group. For reference, the most common basis for is L_{\mathbf{x}} = \begin{bmatrix}0&0&0\\0&0&-1\\0&1&0\end{bmatrix} , \quad L_{\mathbf{y}} = \begin{bmatrix}0&0&1\\0&0&0\\-1&0&0\end{bmatrix} , \quad L_{\mathbf{z}} = \begin{bmatrix}0&-1&0\\1&0&0\\0&0&0\end{bmatrix}. \begin{align} \exp( A ) &= \exp\bigl(\theta(\mathbf{u}\cdot\mathbf{L})\bigr) \\ &= \exp \left( \begin{bmatrix} 0 & -z \theta & y \theta \\ z \theta & 0&-x \theta \\ -y \theta & x \theta & 0 \end{bmatrix} \right) \\ &= I + \sin \theta \ \mathbf{u}\cdot\mathbf{L} + (1-\cos \theta)(\mathbf{u}\cdot\mathbf{L} )^2 , \end{align} where \mathbf{u}\cdot\mathbf{L} = \begin{bmatrix} 0 & -z & y \\ z & 0&-x \\ -y & x & 0 \end{bmatrix} . This is the matrix for a rotation around axis by the angle . For full detail, see exponential map SO(3). Z = C(X, Y) = X + Y + \tfrac{1}{2} [X, Y] + \tfrac{1}{12} \bigl[X,[X,Y]\bigr] - \tfrac{1}{12} \bigl[Y,[X,Y]\bigr] + \cdots . In the case, the general infinite expansion has a compact form, Z = \alpha X + \beta Y + \gamma[X, Y], for suitable trigonometric function coefficients, detailed in the Baker–Campbell–Hausdorff formula for SO(3). As a group identity, the above holds for all faithful representations, including the doublet (spinor representation), which is simpler. The same explicit formula thus follows straightforwardly through Pauli matrices; see the derivation for SU(2). For the general case, one might use Ref. \mathbb{H} \supset \{q \in \mathbb{H}: \|q\| = 1\} \ni w + \mathbf{i}x + \mathbf{j}y + \mathbf{k}z \mapsto \begin{bmatrix} 1 - 2 y^2 - 2 z^2 & 2 x y - 2 z w & 2 x z + 2 y w \\ 2 x y + 2 z w & 1 - 2 x^2 - 2 z^2 & 2 y z - 2 x w \\ 2 x z - 2 y w & 2 y z + 2 x w & 1 - 2 x^2 - 2 y^2 \end{bmatrix} \in \mathrm{SO}(3), and \mathrm{SU}(2) \ni \begin{bmatrix} \alpha & \beta \\ -\overline{\beta} & \overline{\alpha} \end{bmatrix} \mapsto \begin{bmatrix} \frac{1}{2}\left(\alpha^2 - \beta^2 + \overline{\alpha^2} - \overline{\beta^2}\right) & \frac{i}{2}\left(-\alpha^2 - \beta^2 + \overline{\alpha^2} + \overline{\beta^2}\right) & -\alpha\beta - \overline{\alpha}\overline{\beta} \\ \frac{i}{2}\left(\alpha^2 - \beta^2 - \overline{\alpha^2} + \overline{\beta^2}\right) & \frac{i}{2}\left(\alpha^2 + \beta^2 + \overline{\alpha^2} + \overline{\beta^2}\right) & -i\left(+\alpha\beta - \overline{\alpha}\overline{\beta}\right) \\ \alpha\overline{\beta} + \overline{\alpha}\beta & i\left(-\alpha\overline{\beta} + \overline{\alpha}\beta\right) & \alpha\overline{\alpha} - \beta\overline{\beta} \end{bmatrix} \in \mathrm{SO}(3). For a detailed account of the and the quaternionic covering, see spin group SO(3). Many features of these cases are the same for higher dimensions. The coverings are all two-to-one, with , , having fundamental group . The natural setting for these groups is within a Clifford algebra. One type of action of the rotations is produced by a kind of "sandwich", denoted by . More importantly in applications to physics, the corresponding spin representation of the Lie algebra sits inside the Clifford algebra. It can be exponentiated in the usual way to give rise to a representation, also known as projective representation of the rotation group. This is the case with SO(3) and SU(2), where the representation can be viewed as an "inverse" of the covering map. By properties of covering maps, the inverse can be chosen ono-to-one as a local section, but not globally. I + A \, d\theta , where is vanishingly small and , for instance with , dL_{x} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & -d\theta \\ 0 & d\theta & 1 \end{bmatrix}. The computation rules are as usual except that infinitesimals of second order are routinely dropped. With these rules, these matrices do not satisfy all the same properties as ordinary finite rotation matrices under the usual treatment of infinitesimals. It turns out that the order in which infinitesimal rotations are applied is irrelevant. To see this exemplified, consult infinitesimal rotations SO(3). Q = \begin{bmatrix} 1 - 2 y^2 - 2 z^2 & 2 x y - 2 z w & 2 x z + 2 y w \\ 2 x y + 2 z w & 1 - 2 x^2 - 2 z^2 & 2 y z - 2 x w \\ 2 x z - 2 y w & 2 y z + 2 x w & 1 - 2 x^2 - 2 y^2 \end{bmatrix} . Now every quaternion component appears multiplied by two in a term of degree two, and if all such terms are zero what is left is an identity matrix. This leads to an efficient, robust conversion from any quaternion – whether unit or non-unit – to a rotation matrix. Given: \begin{align} n &= w \times w + x \times x + y \times y + z \times z \\ s &= \begin{cases} 0 &\text{if } n = 0 \\ \frac{2}{n} &\text{otherwise} \end{cases} \\ \end{align} we can calculate Q = \begin{bmatrix} 1 - s(yy + zz) & s(xy - wz) & s(xz + wy) \\ s(xy + wz) & 1 - s(xx + zz) & s(yz - wx) \\ s(xz - wy) & s(yz + wx) & 1 - s(xx + yy) \end{bmatrix} Freed from the demand for a unit quaternion, we find that nonzero quaternions act as homogeneous coordinates for rotation matrices. The Cayley transform, discussed earlier, is obtained by scaling the quaternion so that its component is 1. For a 180° rotation around any axis, will be zero, which explains the Cayley limitation. The sum of the entries along the main diagonal (the trace), plus one, equals , which is . Thus we can write the trace itself as ; and from the previous version of the matrix we see that the diagonal entries themselves have the same form: , , and . So we can easily compare the magnitudes of all four quaternion components using the matrix diagonal. We can, in fact, obtain all four magnitudes using sums and square roots, and choose consistent signs using the skew-symmetric part of the off-diagonal entries: \begin{align} t &= \operatorname{tr} Q = Q_{xx} + Q_{yy} + Q_{zz} \quad (\text{the trace of }Q) \\ r &= \sqrt{1 + t} \\ w &= \tfrac{1}{2} r \\ x &= \operatorname{sgn}\left(Q_{zy} - Q_{yz}\right)\left|\tfrac12 \sqrt{1 + Q_{xx} - Q_{yy} - Q_{zz}}\right| \\ y &= \operatorname{sgn}\left(Q_{xz} - Q_{zx}\right)\left|\tfrac12 \sqrt{1 - Q_{xx} + Q_{yy} - Q_{zz}}\right| \\ z &= \operatorname{sgn}\left(Q_{yx} - Q_{xy}\right)\left|\tfrac12 \sqrt{1 - Q_{xx} - Q_{yy} + Q_{zz}}\right| \end{align} Alternatively, use a single square root and division \begin{align} t &= \operatorname{tr} Q = Q_{xx} + Q_{yy} + Q_{zz} \\ r &= \sqrt{1 + t} \\ s &= \tfrac{1}{2r} \\ w &= \tfrac{1}{2} r \\ x &= \left(Q_{zy} - Q_{yz}\right)s \\ y &= \left(Q_{xz} - Q_{zx}\right)s \\ z &= \left(Q_{yx} - Q_{xy}\right)s \end{align} This is numerically stable so long as the trace, , is not negative; otherwise, we risk dividing by (nearly) zero. In that case, suppose is the largest diagonal entry, so will have the largest magnitude (the other cases are derived by cyclic permutation); then the following is safe. \begin{align} r &= \sqrt{1 + Q_{xx} - Q_{yy} - Q_{zz}} \\ s &= \tfrac{1}{2r} \\ w &= \left(Q_{zy} - Q_{yz}\right)s \\ x &= \tfrac12 r \\ y &= \left(Q_{xy} + Q_{yx}\right)s \\ z &= \left(Q_{zx} + Q_{xz}\right)s \end{align} If the matrix contains significant error, such as accumulated numerical error, we may construct a symmetric matrix, K = \frac13 \begin{bmatrix} Q_{xx}-Q_{yy}-Q_{zz} & Q_{yx}+Q_{xy} & Q_{zx}+Q_{xz} & Q_{zy}-Q_{yz} \\ Q_{yx}+Q_{xy} & Q_{yy}-Q_{xx}-Q_{zz} & Q_{zy}+Q_{yz} & Q_{xz}-Q_{zx} \\ Q_{zx}+Q_{xz} & Q_{zy}+Q_{yz} & Q_{zz}-Q_{xx}-Q_{yy} & Q_{yx}-Q_{xy} \\ Q_{zy}-Q_{yz} & Q_{xz}-Q_{zx} & Q_{yx}-Q_{xy} & Q_{xx}+Q_{yy}+Q_{zz} \end{bmatrix} , and find the eigenvector, , of its largest magnitude eigenvalue. (If is truly a rotation matrix, that value will be 1.) The quaternion so obtained will correspond to the rotation matrix closest to the given matrix (Note: formulation of the cited article is post-multiplied, works with row vectors). Consider a example. Including constraints, we seek to minimize \begin{align} &\left(Q_{xx} - M_{xx}\right)^2 + \left(Q_{xy} - M_{xy}\right)^2 + \left(Q_{yx} - M_{yx}\right)^2 + \left(Q_{yy} - M_{yy}\right)^2 \\ &\quad {}+ \left(Q_{xx}^2 + Q_{yx}^2 - 1\right)Y_{xx} + \left(Q_{xy}^2 + Q_{yy}^2 - 1\right)Y_{yy} + 2\left(Q_{xx} Q_{xy} + Q_{yx} Q_{yy}\right)Y_{xy} . \end{align} Taking the derivative with respect to , , , in turn, we assemble a matrix. 2\begin{bmatrix} Q_{xx} - M_{xx} + Q_{xx} Y_{xx} + Q_{xy} Y_{xy} & Q_{xy} - M_{xy} + Q_{xx} Y_{xy} + Q_{xy} Y_{yy} \\ Q_{yx} - M_{yx} + Q_{yx} Y_{xx} + Q_{yy} Y_{xy} & Q_{yy} - M_{yy} + Q_{yx} Y_{xy} + Q_{yy} Y_{yy} \end{bmatrix} In general, we obtain the equation 0 = 2(Q - M) + 2QY , so that M = Q(I + Y) = QS , where is orthogonal and is symmetric. To ensure a minimum, the matrix (and hence ) must be positive definite. Linear algebra calls the polar decomposition of , with the positive square root of . S^2 = \left(Q^\mathsf{T} M\right)^\mathsf{T} \left(Q^\mathsf{T} M\right) = M^\mathsf{T} Q Q^\mathsf{T} M = M^\mathsf{T} M When is non-singular, the and factors of the polar decomposition are uniquely determined. However, the determinant of is positive because is positive definite, so inherits the sign of the determinant of . That is, is only guaranteed to be orthogonal, not a rotation matrix. This is unavoidable; an with negative determinant has no uniquely defined closest rotation matrix. \begin{align} c &= \cos \theta\\ s &= \sin \theta\\ C &= 1-c \end{align} then Q(\theta) = \begin{bmatrix} xxC+c & xyC-zs & xzC+ys\\ yxC+zs & yyC+c & yzC-xs\\ zxC-ys & zyC+xs & zzC+c \end{bmatrix} Determining an axis and angle, like determining a quaternion, is only possible up to the sign; that is, and correspond to the same rotation matrix, just like and . Additionally, axis–angle extraction presents additional difficulties. The angle can be restricted to be from 0° to 180°, but angles are formally ambiguous by multiples of 360°. When the angle is zero, the axis is undefined. When the angle is 180°, the matrix becomes symmetric, which has implications in extracting the axis. Near multiples of 180°, care is needed to avoid numerical problems: in extracting the angle, a two-argument arctangent with equal to avoids the insensitivity of arccos; and in computing the axis magnitude in order to force unit magnitude, a brute-force approach can lose accuracy through underflow . A partial approach is as follows: \begin{align} x &= Q_{zy} - Q_{yz}\\ y &= Q_{xz} - Q_{zx}\\ z &= Q_{yx} - Q_{xy}\\ r &= \sqrt{x^2 + y^2 + z^2}\\ t &= Q_{xx} + Q_{yy} + Q_{zz}\\ \theta &= \operatorname{atan2}(r,t-1)\end{align} The -, -, and -components of the axis would then be divided by . A fully robust approach will use a different algorithm when , the trace of the matrix , is negative, as with quaternion extraction. When is zero because the angle is zero, an axis must be provided from some source other than the matrix. Q(\theta_1,\theta_2,\theta_3)= Q_{\mathbf{z}}(\theta_1) Q_{\mathbf{y}}(\theta_2) Q_{\mathbf{z}}(\theta_3) , while aircraft dynamics may use Q(\theta_1,\theta_2,\theta_3)= Q_{\mathbf{z}}(\theta_3) Q_{\mathbf{y}}(\theta_2) Q_{\mathbf{x}}(\theta_1) . One systematic approach begins with choosing the rightmost axis. Among all permutations of , only two place that axis first; one is an even permutation and the other odd. Choosing parity thus establishes the middle axis. That leaves two choices for the left-most axis, either duplicating the first or not. These three choices gives us variations; we double that to 24 by choosing static or rotating axes. This is enough to construct a matrix from angles, but triples differing in many ways can give the same rotation matrix. For example, suppose we use the convention above; then we have the following equivalent pairs: Angles for any order can be found using a concise common routine ( ; ). The problem of singular alignment, the mathematical analog of physical gimbal lock, occurs when the middle rotation aligns the axes of the first and last rotations. It afflicts every axis order at either even or odd multiples of 90°. These singularities are not characteristic of the rotation matrix as such, and only occur with the usage of Euler angles. The singularities are avoided when considering and manipulating the rotation matrix as orthonormal row vectors (in 3D applications often named the right-vector, up-vector and out-vector) instead of as angles. The singularities are also avoided when working with quaternions. R:=I+y x^\mathsf{T}-x y^\mathsf{T}+\frac{1}{1+\langle x,y\rangle}\left(yx^\mathsf{T}-xy^\mathsf{T}\right)^2 belongs to and maps to . T = \begin{bmatrix} \cos^2\theta & \sin^2\theta & 2\sin\theta\cos\theta \\ \sin^2\theta & \cos^2\theta & 2\sin\theta\cos\theta \\ -\sin\theta\cos\theta & \sin\theta\cos\theta & \cos^2\theta - \sin^2\theta \end{bmatrix} . This is particularly useful in composite laminate design, where plies are often rotated by a certain angle to bring the properties of the laminate closer to isotropic. ==See also== Euler–Rodrigues formula Euler's rotation theorem Rodrigues' rotation formula Plane of rotation Axis–angle representation Rotation group SO(3) Rotation formalisms in three dimensions Rotation operator (vector space) Transformation matrix Yaw-pitch-roll system Kabsch algorithm Isometry Rigid transformation Rotations in 4-dimensional Euclidean space Trigonometric Identities Stream function Cauchy-Riemann equations Versor ==Remarks== ==External links== Rotation matrices at Mathworld Math Awareness Month 2000 interactive demo (requires Java) Rotation Matrices at MathPages A parametrization of SOn(R) by generalized Euler Angles Rotation about any point

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Rotation matrix". 1791075233. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1378352759

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·