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}
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 :
Rv=\begin{bmatrix} \cos\theta&-\sin\theta\ \sin\theta&\cos\theta\end{bmatrix}\begin{bmatrix}x\ y\end{bmatrix} = \begin{bmatrix}x\cos\theta-y\sin\theta\\ x\sin\theta+y\cos\theta \end{bmatrix}.
If and are the endpoint coordinates of a vector, where is cosine and is sine, then the above equations become the trigonometric summation angle formulae. Indeed, a rotation matrix can be seen as 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 (on the left). 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). These combine proper rotations 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, 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}.
For example, when the vector
\hat{x
\begin{bmatrix} \cos\theta\\ \sin\theta\\ \end{bmatrix},
and when the vector
\hat{y
\begin{bmatrix} -\sin\theta\\ \cos\theta\\ \end{bmatrix}.
The direction of vector rotation is counterclockwise if is positive (e.g. 90°), and clockwise if is negative (e.g. −90°) for
R(\theta)
R(-\theta)=\begin{bmatrix} \cos\theta&\sin\theta\\ -\sin\theta&\cos\theta\\ \end{bmatrix}.
The two-dimensional case is the only non-trivial (i.e. not one-dimensional) case where the rotation matrices group is commutative, so that it does not matter in which order multiple rotations are performed. An alternative convention uses rotating axes,[1] and the above matrices also represent a rotation of the axes clockwise through an angle .
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.[2]
See below for other alternative conventions which may change the sense of the rotation produced by a rotation matrix.
Particularly useful are the matrices
\begin{bmatrix} 0&-1\\[3pt] 1&0\\ \end{bmatrix}, \begin{bmatrix} -1&0\\[3pt] 0&-1\\ \end{bmatrix}, \begin{bmatrix} 0&1\\[3pt] -1&0\\ \end{bmatrix}
Since
\begin{bmatrix}0&-1\ 1&0\end{bmatrix}2 = \begin{bmatrix}-1&0\ 0&-1\end{bmatrix} =-I,
\begin{bmatrix}x&-y\ y&x\end{bmatrix}
If one identifies
R2
C
(a,b)\mapstoa+ib,
R2
As every rotation matrix can be written
\begin{pmatrix}\cost&-\sint\ \sint&\cost\end{pmatrix},
\cost+i\sint=eit
See also: Rotation formalisms in three dimensions.
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 ⋅ \vec{x}
\begin{alignat}{1} Rx(\theta)&=\begin{bmatrix} 1&0&0\\ 0&\cos\theta&-\sin\theta\\[3pt] 0&\sin\theta&\cos\theta\\[3pt] \end{bmatrix}\\[6pt] Ry(\theta)&=\begin{bmatrix} \cos\theta&0&\sin\theta\\[3pt] 0&1&0\\[3pt] -\sin\theta&0&\cos\theta\\ \end{bmatrix}\\[6pt] Rz(\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 :
\circ) | |
R | |
z(90 |
\begin{bmatrix}1\ 0\ 0\ \end{bmatrix}= \begin{bmatrix}\cos90\circ&-\sin90\circ&0\ \sin90\circ& \cos90\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.
Other 3D rotation matrices can be obtained from these three using matrix multiplication. For example, the product
\begin{align} R=Rz(\alpha)Ry(\beta)Rx(\gamma)&= \oversetyaw{\begin{bmatrix} \cos\alpha&-\sin\alpha&0\\ \sin\alpha&\cos\alpha&0\\ 0&0&1\\ \end{bmatrix}}\oversetpitch{\begin{bmatrix} \cos\beta&0&\sin\beta\\ 0&1&0\\ -\sin\beta&0&\cos\beta\\ \end{bmatrix}}\oversetroll{\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=Rz(\gamma)Ry(\beta)Rx(\alpha)&=\begin{bmatrix} \cos\gamma&-\sin\gamma&0\\ \sin\gamma&\cos\gamma&0\\ 0&0&1\\ \end{bmatrix}\begin{bmatrix} \cos\beta&0&\sin\beta\\ 0&1&0\\ -\sin\beta&0&\cos\beta\\ \end{bmatrix}\begin{bmatrix} 1&0&0\\ 0&\cos\alpha&-\sin\alpha\\ 0&\sin\alpha&\cos\alpha\\ \end{bmatrix}\\ &=\begin{bmatrix} \cos\beta\cos\gamma&\sin\alpha\sin\beta\cos\gamma-\cos\alpha\sin\gamma&\cos\alpha\sin\beta\cos\gamma+\sin\alpha\sin\gamma\\ \cos\beta\sin\gamma&\sin\alpha\sin\beta\sin\gamma+\cos\alpha\cos\gamma&\cos\alpha\sin\beta\sin\gamma-\sin\alpha\cos\gamma\\ -\sin\beta&\sin\alpha\cos\beta&\cos\alpha\cos\beta\\ \end{bmatrix}\end{align}
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.[4]
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.
Given a rotation matrix, a vector parallel to the rotation axis must satisfy
Ru=u,
Further, the equation may be rewritten
Ru=Iu\implies\left(R-I\right)u=0,
Viewed in another way, 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&=RT0+0\\ &=RT\left(R-I\right)u+\left(R-I\right)u\\ &=\left(RTR-RT+R-I\right)u\\ &=\left(I-RT+R-I\right)u\\ &=\left(R-RT\right)u \end{align}
Since is a skew-symmetric matrix, we can choose such that
[u] x =\left(R-RT\right).
\left(R-RT\right)u=[u] x u=u x u=0
Therefore, if
R=\begin{bmatrix}a&b&c\ d&e&f\ g&h&i\ \end{bmatrix},
u=\begin{bmatrix}h-f\ c-g\ d-b\ \end{bmatrix}.
This does not work if is symmetric. Above, if is zero, then all subsequent steps are invalid. In this case, it is necessary to diagonalize and find the eigenvector corresponding to an eigenvalue of 1.
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(
\operatorname{tr | |
(R) |
-1}{2}\right).
For the rotation axis
n=(n1,n2,n3)
\left\{\begin{matrix} \cos\theta&=&\dfrac{\operatorname{tr}(R)-1}{2}\\ \sin\theta&=&-\dfrac{\operatorname{tr}(KnR)}{2} \end{matrix}\right.
where
Kn=\begin{bmatrix} 0&-n3&n2\\ n3&0&-n1\\ -n2&n1&0\\ \end{bmatrix}
The matrix of a proper rotation by angle around the axis, a unit vector with, is given by:[6] [7] [8] [9]
R=\begin{bmatrix}
2 | |
u | |
x |
\left(1-\cos\theta\right)+\cos\theta&uxuy\left(1-\cos\theta\right)-uz\sin\theta&uxuz\left(1-\cos\theta\right)+uy\sin\theta\ uxuy\left(1-\cos\theta\right)+uz\sin\theta&
2\left(1-\cos | |
u | |
y |
\theta\right)+\cos\theta&uyuz\left(1-\cos\theta\right)-ux\sin\theta\ uxuz\left(1-\cos\theta\right)-uy\sin\theta&uyuz\left(1-\cos\theta\right)+ux\sin\theta&
2\left(1-\cos | |
u | |
z |
\theta\right)+\cos\theta \end{bmatrix}.
A derivation of this matrix from first principles can be found in section 9.2 here.[10] The basic idea to derive this matrix is dividing the problem into few known simple steps.
This can be written more concisely as [11]
R=(\cos\theta)I+(\sin\theta)[u] x +(1-\cos\theta)(u ⊗ u),
Rjk
| ||||
=\begin{cases} \cos |
| ||||
+\sin |
2-1\right), | |
\left(2u | |
j |
&ifj=k\\ 2uju
| ||||
k\sin |
-\varepsilonjklul\sin\theta, &ifj ≠ 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[12]
u ⊗ u=uuT=
2 | |
\begin{bmatrix} u | |
x |
&uxuy&uxuz\\[3pt] uxuy&
2 | |
u | |
y |
&uyuz\\[3pt] uxuz&uyuz&
2 \end{bmatrix}, | |
u | |
z |
[u] x =\begin{bmatrix} 0&-uz&uy\\[3pt] uz&0&-ux\\[3pt] -uy&ux&0 \end{bmatrix}.
In
R3
Ru(\theta)x=u(u ⋅ x)+\cos\left(\theta\right)(u x x) x u+\sin\left(\theta\right)(u x x)
or equivalently:
Ru(\theta)x=x\cos(\theta)+u(x ⋅ u)(1-\cos(\theta))-x x u\sin{\theta}
This can also be written in tensor notation as:[13]
(Ru(\theta)x)i=(Ru(\theta))ij{x
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},u)
Ru(\theta)\boldsymbol{\alpha}=\cos\left(\theta\right)\boldsymbol{\alpha}+\sin\left(\theta\right)\boldsymbol{\beta}, Ru(\theta)\boldsymbol{\beta}=-\sin\left(\theta\right)\boldsymbol{\alpha}+\cos\left(\theta\right)\boldsymbol{\beta}, Ru(\theta)u=u.
Note the striking merely apparent differences to the equivalent Lie-algebraic formulation below.
For any -dimensional rotation matrix acting on
Rn,
RT=R-1
\detR=\pm1
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(RT\right)\det\left(R-I\right) =\det\left(RTR-RT\right) =\det\left(I-RT\right)\\ &=\det(I-R) =\left(-1\right)n\det\left(R-I\right) =-\det\left(R-I\right). \end{align}
Here is the identity matrix, and we use, as well as since is odd. Therefore,, meaning there is a nonzero vector with, that is, a fixed eigenvector. There may also be pairs of fixed eigenvectors in the even-dimensional subspace orthogonal to, so the total dimension of fixed eigenvectors is odd.
For example, in 2-space, a rotation by angle has eigenvalues and, so there is no axis of rotation except when, the case of the null rotation. In 3-space, the axis of a non-null proper rotation is always a unique line, and a rotation around this axis by angle has eigenvalues . In 4-space, the four eigenvalues are of the form . The null rotation has . The case of is called a simple rotation, with two unit eigenvalues forming an axis plane, and a two-dimensional rotation orthogonal to the axis plane. Otherwise, there is no axis plane. The case of is called an isoclinic rotation, having eigenvalues repeated twice, so every vector is rotated through an angle .
The trace of a rotation matrix is equal to the sum of its eigenvalues. For, a rotation by angle has trace . For, a rotation around any axis by angle has trace . For, and the trace is, which becomes for an isoclinic rotation.
Q=\begin{bmatrix}0&1\ -1&0\end{bmatrix}
corresponds to a 90° planar rotation clockwise about the origin.
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 .
Q=\begin{bmatrix}1&0&0\ 0&
\sqrt{3 | |
corresponds to a −30° rotation around the -axis in three-dimensional space.
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.
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 .
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.
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).
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.
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.
In Euclidean geometry, a rotation is an example of an isometry, a transformation that moves points without changing the distances between them. Rotations are distinguished from other isometries by two additional properties: they leave (at least) one point fixed, and they leave "handedness" unchanged. In contrast, a translation moves every point, a reflection exchanges left- and right-handed ordering, a glide reflection does both, and an improper rotation combines a change in handedness with a normal rotation.
If a fixed point is taken as the origin of a Cartesian coordinate system, then every point can be given coordinates as a displacement from the origin. Thus one may work with the vector space of displacements instead of the points themselves. Now suppose are the coordinates of the vector from the origin to point . Choose an orthonormal basis for our coordinates; then the squared distance to, by Pythagoras, is
d2(O,P)=\|p\|2=
n | |
\sum | |
r=1 |
2 | |
p | |
r |
\|p\|2=\begin{bmatrix}p1 … pn\end{bmatrix}\begin{bmatrix}p1\ \vdots\ pn\end{bmatrix}=pTp.
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
pTp=(Qp)T(Qp),
\begin{align} pTIp&{}=\left(pTQT\right)(Qp)\\ &{}=pT\left(QTQ\right)p. \end{align}
QTQ=I.
\detQ=+1.
The inverse of a rotation matrix is its transpose, which is also a rotation matrix:
\begin{align}\left(QT\right)T\left(QT\right)&=QQT=I\ \detQT&=\detQ=+1.\end{align}
\begin{align} \left(Q1
T | |
Q | |
2\right) |
\left(Q1Q2\right)&=
T | |
Q | |
2 |
T | |
\left(Q | |
1 |
Q1\right)Q2=I\\ \det\left(Q1Q2\right)&=\left(\detQ1\right)\left(\detQ2\right)=+1. \end{align}
\begin{align} Q1&=\begin{bmatrix}0&-1&0\ 1&0&0\ 0&0&1\end{bmatrix}& Q2&=\begin{bmatrix}0&0&1\ 0&1&0\ -1&0&0\end{bmatrix}\\ Q1Q2&=\begin{bmatrix}0&-1&0\ 0&0&1\ -1&0&0\end{bmatrix}& Q2Q1&=\begin{bmatrix}0&0&1\ 1&0&0\ 0&1&0\end{bmatrix}. \end{align}
The interpretation of a rotation matrix can be subject to many ambiguities.
In most cases the effect of the ambiguity is equivalent to the effect of a rotation matrix inversion (for these orthogonal matrices equivalently matrix transpose).
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.
Consider 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}.
Qv=λv,
0=(λI-Q)v.
\begin{align} 0&{}=\det(λI-Q)\\ &{}=λ3-\tfrac{39}{25}λ2+\tfrac{39}{25}λ-1\\ &{}=(λ-1)\left(λ2-\tfrac{14}{25}λ+1\right). \end{align}
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.
The constraints on a rotation matrix imply that it must have the form
Q=\begin{bmatrix}a&-b\ b&a\end{bmatrix}
Now consider the first column of a rotation matrix,
\begin{bmatrix}a\\b\\c\end{bmatrix}.
\begin{bmatrix}r\\0\\c\end{bmatrix},
QxzQxyQ=\begin{bmatrix}1&0&0\\0&\ast&\ast\\0&\ast&\ast\end{bmatrix}.
QyzQxzQxyQ=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix},
Q=
-1 | |
Q | |
xy |
-1 | |
Q | |
xz |
-1 | |
Q | |
yz |
.
An rotation matrix will have, or
n-1 | |
\sum | |
k=1 |
k=
1 | |
2 |
n(n-1)
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.
A rotation matrix such as
Q3=\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,
Q2= \begin{bmatrix} \cos\theta&-\sin\theta\ \sin\theta&\cos\theta \end{bmatrix},
is embedded in the upper left corner:
Q3=\left[\begin{matrix}Q2&0\ 0T&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} Qx(\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] Qy(\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] Qz(\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} Qu(\theta) &=\begin{bmatrix} 0&-z&y\\ z&0&-x\\ -y&x&0 \end{bmatrix}\sin\theta+\left(I-uuT\right)\cos\theta+uuT\\[8px] &=\begin{bmatrix} \left(1-x2\right)c\theta+x2& -zs\theta-xyc\theta+xy& ys\theta-xzc\theta+xz\\ zs\theta-xyc\theta+xy& \left(1-y2\right)c\theta+y2& -xs\theta-yzc\theta+yz\\ -ys\theta-xzc\theta+xz& xs\theta-yzc\theta+yz& \left(1-z2\right)c\theta+z2 \end{bmatrix}\\[8px] &=\begin{bmatrix} x2(1-c\theta)+c\theta& xy(1-c\theta)-zs\theta& xz(1-c\theta)+ys\theta\\ xy(1-c\theta)+zs\theta& y2(1-c\theta)+c\theta& yz(1-c\theta)-xs\theta\\ xz(1-c\theta)-ys\theta& yz(1-c\theta)+xs\theta& z2(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)\hookrightarrowSO(n+1)\toSn,
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.
See main article: Cayley transform and Skew-symmetric matrix. When an rotation matrix, does not include a −1 eigenvalue, thus none of the planar rotations which it comprises are 180° rotations, then is an invertible matrix. Most rotation matrices fit this description, and for them it can be shown that is a skew-symmetric matrix, . Thus ; and since the diagonal is necessarily zero, and since the upper triangle determines the lower one, contains independent numbers.
Conveniently, is invertible whenever is skew-symmetric; thus we can recover the original matrix using the Cayley transform,
A\mapsto(I+A)(I-A)-1,
In three dimensions, for example, we have
\begin{align} &\begin{bmatrix} 0&-z&y\\ z&0&-x\\ -y&x&0 \end{bmatrix}\mapsto\\[3pt]
1 | |
1+x2+y2+z2 |
&\begin{bmatrix} 1+x2-y2-z2&2xy-2z&2y+2xz\\ 2xy+2z&1-x2+y2-z2&2yz-2x\\ 2xz-2y&2x+2yz&1-x2-y2+z2 \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.
For the 2D case, a rotation matrix can be decomposed into three shear matrices :
\begin{align} R(\theta) &{}=\begin{bmatrix} 1&-\tan
\theta | |
2 |
\\ 0&1 \end{bmatrix} \begin{bmatrix} 1&0\\ \sin\theta&1\end{bmatrix} \begin{bmatrix} 1&-\tan
\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 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&
1 | |
\cos\theta |
\end{bmatrix} \end{align}
Below follow some basic facts about the role of the collection of all rotation matrices of a fixed dimension (here mostly 3) in mathematics and particularly in physics where rotational symmetry is a requirement of every truly fundamental law (due to the assumption of isotropy of space), and where the same symmetry, when present, is a simplifying property of many problems of less fundamental nature. Examples abound in classical mechanics and quantum mechanics. Knowledge of the part of the solutions pertaining to this symmetry applies (with qualifications) to all such problems and it can be factored out of a specific problem at hand, thus reducing its complexity. A prime example – in mathematics and physics – would be the theory of spherical harmonics. Their role in the group theory of the rotation groups is that of being a representation space for the entire set of finite-dimensional irreducible representations of the rotation group SO(3). For this topic, see Rotation group SO(3) § Spherical harmonics.
The main articles listed in each subsection are referred to for more detail.
See main article: Rotation group SO(3). The rotation matrices for each form a group, the special orthogonal group, . This algebraic structure is coupled with a topological structure inherited from
\operatorname{GL}n(\R)
The Lie algebra of is given by
ak{so}(n)=ak{o}(n)=\left\{X\inMn(R)\midX=-XT\right\},
Lx=\begin{bmatrix}0&0&0\\0&0&-1\\0&1&0\end{bmatrix}, Ly=\begin{bmatrix}0&0&1\\0&0&0\\-1&0&0\end{bmatrix}, Lz=\begin{bmatrix}0&-1&0\\1&0&0\\0&0&0\end{bmatrix}.
See main article: Matrix exponential. Connecting the Lie algebra to the Lie group is the exponential map, which is defined using the standard matrix exponential series for For any skew-symmetric matrix, is always a rotation matrix.[14]
An important practical example is the case. In rotation group SO(3), it is shown that one can identify every with an Euler vector, where is a unit magnitude vector.
By the properties of the identification
su(2)\congR3
According to Rodrigues' rotation formula on matrix form, one obtains,
\begin{align} \exp(A)&=\expl(\theta(u ⋅ L)r)\\ &=\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 u ⋅ L+(1-\cos\theta)(u ⋅ L)2, \end{align}
where
u ⋅ 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).
See main article: Baker–Campbell–Hausdorff formula. The BCH formula provides an explicit expression for in terms of a series expansion of nested commutators of and . This general expansion unfolds as[15]
Z=C(X,Y)=X+Y+\tfrac{1}{2}[X,Y]+\tfrac{1}{12}l[X,[X,Y]r]-\tfrac{1}{12}l[Y,[X,Y]r]+ … .
In the case, the general infinite expansion has a compact form,
Z=\alphaX+\betaY+\gamma[X,Y],
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.[16]
See main article: Spin group. The Lie group of rotation matrices,, is not simply connected, so Lie theory tells us it is a homomorphic image of a universal covering group. Often the covering group, which in this case is called the spin group denoted by, is simpler and more natural to work with.
In the case of planar rotations, SO(2) is topologically a circle, . Its universal covering group, Spin(2), is isomorphic to the real line,, under addition. Whenever angles of arbitrary magnitude are used one is taking advantage of the convenience of the universal cover. Every rotation matrix is produced by a countable infinity of angles, separated by integer multiples of 2. Correspondingly, the fundamental group of is isomorphic to the integers, .
In the case of spatial rotations, SO(3) is topologically equivalent to three-dimensional real projective space, . Its universal covering group, Spin(3), is isomorphic to the, . Every rotation matrix is produced by two opposite points on the sphere. Correspondingly, the fundamental group of SO(3) is isomorphic to the two-element group, .
We can also describe Spin(3) as isomorphic to quaternions of unit norm under multiplication, or to certain real matrices, or to complex special unitary matrices, namely SU(2). The covering maps for the first and the last case are given by
H\supset\{q\inH:\|q\|=1\}\niw+ix+jy+kz\mapsto \begin{bmatrix} 1-2y2-2z2&2xy-2zw&2xz+2yw\\ 2xy+2zw&1-2x2-2z2&2yz-2xw\\ 2xz-2yw&2yz+2xw&1-2x2-2y2 \end{bmatrix}\inSO(3),
SU(2)\ni\begin{bmatrix} \alpha&\beta\\ -\overline{\beta}&\overline{\alpha} \end{bmatrix}\mapsto\begin{bmatrix}
1 | |
2 |
\left(\alpha2-\beta2+\overline{\alpha2}-\overline{\beta2}\right)&
i | |
2 |
\left(-\alpha2-\beta2+\overline{\alpha2}+\overline{\beta2}\right)& -\alpha\beta-\overline{\alpha}\overline{\beta}\\
i | |
2 |
\left(\alpha2-\beta2-\overline{\alpha2}+\overline{\beta2}\right)&
i | |
2 |
\left(\alpha2+\beta2+\overline{\alpha2}+\overline{\beta2}\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}\inSO(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.
See main article: Infinitesimal rotation matrix. The matrices in the Lie algebra are not themselves rotations; the skew-symmetric matrices are derivatives, proportional differences of rotations. An actual "differential rotation", or infinitesimal rotation matrix has the form
I+Ad\theta,
dLx=\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).
We have seen the existence of several decompositions that apply in any dimension, namely independent planes, sequential angles, and nested dimensions. In all these cases we can either decompose a matrix or construct one. We have also given special attention to rotation matrices, and these warrant further attention, in both directions .
See main article: Quaternions and spatial rotation.
Given the unit quaternion, the equivalent pre-multiplied (to be used with column vectors) rotation matrix is [17]
Q=\begin{bmatrix} 1-2y2-2z2&2xy-2zw&2xz+2yw\\ 2xy+2zw&1-2x2-2z2&2yz-2xw\\ 2xz-2yw&2yz+2xw&1-2x2-2y2 \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 x w+x x x+y x y+z x z\\ s&=\begin{cases} 0&ifn=0\\
2 | |
n |
&otherwise \end{cases}\\ \end{align}
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}
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=Qxx+Qyy+Qzz (thetraceofQ)\\ r&=\sqrt{1+t}\\ w&=\tfrac{1}{2}r\\ x&=\operatorname{sgn}\left(Qzy-Qyz\right)\left|\tfrac12\sqrt{1+Qxx-Qyy-Qzz
Alternatively, use a single square root and division
\begin{align} t&=\operatorname{tr}Q=Qxx+Qyy+Qzz\\ r&=\sqrt{1+t}\\ s&=\tfrac{1}{2r}\\ w&=\tfrac{1}{2}r\\ x&=\left(Qzy-Qyz\right)s\\ y&=\left(Qxz-Qzx\right)s\\ z&=\left(Qyx-Qxy\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+Qxx-Qyy-Qzz
If the matrix contains significant error, such as accumulated numerical error, we may construct a symmetric matrix,
K=
13 | |
\begin{bmatrix} |
Qxx-Qyy-Qzz&Qyx+Qxy&Qzx+Qxz&Qzy-Qyz\\ Qyx+Qxy&Qyy-Qxx-Qzz&Qzy+Qyz&Qxz-Qzx\\ Qzx+Qxz&Qzy+Qyz&Qzz-Qxx-Qyy&Qyx-Qxy\\ Qzy-Qyz&Qxz-Qzx&Qyx-Qxy&Qxx+Qyy+Qzz\end{bmatrix},
If the matrix is nonsingular, its columns are linearly independent vectors; thus the Gram–Schmidt process can adjust them to be an orthonormal basis. Stated in terms of numerical linear algebra, we convert to an orthogonal matrix,, using QR decomposition. However, we often prefer a closest to, which this method does not accomplish. For that, the tool we want is the polar decomposition (;).
To measure closeness, we may use any matrix norm invariant under orthogonal transformations. A convenient choice is the Frobenius norm,, squared, which is the sum of the squares of the element differences. Writing this in terms of the trace,, our goal is,
Find minimizing, subject to .
Though written in matrix terms, the objective function is just a quadratic polynomial. We can minimize it in the usual way, by finding where its derivative is zero. For a matrix, the orthogonality constraint implies six scalar equalities that the entries of must satisfy. To incorporate the constraint(s), we may employ a standard technique, Lagrange multipliers, assembled as a symmetric matrix, . Thus our method is:
Differentiate with respect to (the entries of), and equate to zero.
Consider a example. Including constraints, we seek to minimize
\begin{align} &\left(Qxx-Mxx\right)2+\left(Qxy-Mxy\right)2+\left(Qyx-Myx\right)2+\left(Qyy-Myy\right)2\\ & {}+
2 | |
\left(Q | |
xx |
+
2 | |
Q | |
yx |
-1\right)Yxx+
2 | |
\left(Q | |
xy |
+
2 | |
Q | |
yy |
-1\right)Yyy+2\left(QxxQxy+QyxQyy\right)Yxy. \end{align}
Taking the derivative with respect to,,, in turn, we assemble a matrix.
2\begin{bmatrix} Qxx-Mxx+QxxYxx+QxyYxy&Qxy-Mxy+QxxYxy+QxyYyy\\ Qyx-Myx+QyxYxx+QyyYxy&Qyy-Myy+QyxYxy+QyyYyy\end{bmatrix}
In general, we obtain the equation
0=2(Q-M)+2QY,
M=Q(I+Y)=QS,
S2=\left(QTM\right)T\left(QTM\right)=MTQQTM=MTM
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.
See main article: Axis–angle representation. To efficiently construct a rotation matrix from an angle and a unit axis, we can take advantage of symmetry and skew-symmetry within the entries. If,, and are the components of the unit vector representing the axis, and
\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&=Qzy-Qyz\\ y&=Qxz-Qzx\\ z&=Qyx-Qxy\\ r&=\sqrt{x2+y2+z2}\\ t&=Qxx+Qyy+Qzz\\ \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.
Complexity of conversion escalates with Euler angles (used here in the broad sense). The first difficulty is to establish which of the twenty-four variations of Cartesian axis order we will use. Suppose the three angles are,, ; physics and chemistry may interpret these as
Q(\theta1,\theta2,\theta3)=Qz(\theta1)Qy(\theta2)Qz(\theta3),
Q(\theta1,\theta2,\theta3)=Qz(\theta3)Qy(\theta2)Qx(\theta1).
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:
(90°, | 45°, | −105°) | ≡ | (−270°, | −315°, | 255°) | multiples of 360° | |
(72°, | 0°, | 0°) | ≡ | (40°, | 0°, | 32°) | singular alignment | |
(45°, | 60°, | −30°) | ≡ | (−135°, | −60°, | 150°) | bistable flip |
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.
In some instances it is interesting to describe a rotation by specifying how a vector is mapped into another through the shortest path (smallest angle). In
R3
R:=I+yxT-x
| ||||
y |
\left(yxT-xyT\right)2
We sometimes need to generate a uniformly distributed random rotation matrix. It seems intuitively clear in two dimensions that this means the rotation angle is uniformly distributed between 0 and 2. That intuition is correct, but does not carry over to higher dimensions. For example, if we decompose rotation matrices in axis–angle form, the angle should not be uniformly distributed; the probability that (the magnitude of) the angle is at most should be, for .
Since is a connected and locally compact Lie group, we have a simple standard criterion for uniformity, namely that the distribution be unchanged when composed with any arbitrary rotation (a Lie group "translation"). This definition corresponds to what is called Haar measure. show how to use the Cayley transform to generate and test matrices according to this criterion.
We can also generate a uniform distribution in any dimension using the subgroup algorithm of . This recursively exploits the nested dimensions group structure of, as follows. Generate a uniform angle and construct a rotation matrix. To step from to, generate a vector uniformly distributed on the -sphere, embed the matrix in the next larger size with last column, and rotate the larger matrix so the last column becomes .
As usual, we have special alternatives for the case. Each of these methods begins with three independent random scalars uniformly distributed on the unit interval. takes advantage of the odd dimension to change a Householder reflection to a rotation by negation, and uses that to aim the axis of a uniform planar rotation.
Another method uses unit quaternions. Multiplication of rotation matrices is homomorphic to multiplication of quaternions, and multiplication by a unit quaternion rotates the unit sphere. Since the homomorphism is a local isometry, we immediately conclude that to produce a uniform distribution on SO(3) we may use a uniform distribution on . In practice: create a four-element vector where each element is a sampling of a normal distribution. Normalize its length and you have a uniformly sampled random unit quaternion which represents a uniformly sampled random rotation. Note that the aforementioned only applies to rotations in dimension 3. For a generalised idea of quaternions, one should look into Rotors.
Euler angles can also be used, though not with each angle uniformly distributed (;).
For the axis–angle form, the axis is uniformly distributed over the unit sphere of directions,, while the angle has the nonuniform distribution over noted previously .
u ⊗ u=l([u] x r)2+{I}
R=I+(\sin\theta)[u] x +(1-\cos\theta)l([u] x r)2.
e2A-
I+A | |
I-A |
=-\tfrac{2}{3}A3+O\left(A4\right).