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 = [ cos θ − sin θ sin θ cos θ ] ⋅ {\displaystyle R={\begin{bmatrix}\cos \theta &-\sin \theta \\\sin \theta &\cos \theta \end{bmatrix}}\cdot }
rotates points in the xy 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 v = (x, y), it should be written as a column vector, and multiplied by the matrix R:
R v = [ cos θ − sin θ sin θ cos θ ] [ x y ] = x [ cos θ sin θ ] + y [ − sin θ cos θ ] = [ x cos θ − y sin θ x sin θ + y cos θ ] . {\displaystyle 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 x and y are the coordinates of the endpoint of a vector with the length r and the angle ϕ {\displaystyle \phi } with respect to the x-axis, so that x = r cos ϕ {\textstyle x=r\cos \phi } and y = r sin ϕ {\displaystyle y=r\sin \phi } , then the above equations become the trigonometric summation angle formulae: R v = r [ cos ϕ cos θ − sin ϕ sin θ cos ϕ sin θ + sin ϕ cos θ ] = r [ cos ( ϕ + θ ) sin ( ϕ + θ ) ] . {\displaystyle 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 x-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 (y counterclockwise from x) by pre-multiplication (the rotation matrix R applied on the left of the column vector v 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 R is a rotation matrix if and only if RT = R−1 and det R = 1. The set of all orthogonal matrices of size n with determinant +1 is a representation of a group known as the special orthogonal group SO(n), one example of which is the rotation group SO(3). The set of all orthogonal matrices of size n with determinant +1 or −1 is a representation of the (general) orthogonal group O(n).
In two dimensions
In two dimensions, the standard rotation matrix has the following form:
R ( θ ) = [ cos θ − sin θ sin θ cos θ ] . {\displaystyle 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,
[ x ′ y ′ ] = [ cos θ − sin θ sin θ cos θ ] [ x y ] . {\displaystyle {\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 (x′, y′) of a point (x, y) after rotation are
x ′ = x cos θ − y sin θ y ′ = x sin θ + y cos θ . {\displaystyle {\begin{aligned}x'&=x\cos \theta -y\sin \theta \,\\y'&=x\sin \theta +y\cos \theta \,\end{aligned}}.}
Examples For example, when the vector (initially aligned with the x-axis of the Cartesian coordinate system)
x ^ = [ 1 0 ] {\displaystyle \mathbf {\hat {x}} ={\begin{bmatrix}1\\0\\\end{bmatrix}}}
is rotated by an angle θ, its new coordinates are
[ cos θ sin θ ] , {\displaystyle {\begin{bmatrix}\cos \theta \\\sin \theta \\\end{bmatrix}},}
and when the vector (initially aligned with the y-axis of the coordinate system)
y ^ = [ 0 1 ] {\displaystyle \mathbf {\hat {y}} ={\begin{bmatrix}0\\1\\\end{bmatrix}}}
is rotated by an angle θ, its new coordinates are
[ − sin θ cos θ ] . {\displaystyle {\begin{bmatrix}-\sin \theta \\\cos \theta \\\end{bmatrix}}.}
Sense The sense or "direction" of vector rotation (not to be confused with the vector direction) is counterclockwise if θ is positive (e.g. 90°), and clockwise if θ is negative (e.g. −90°) for R ( θ ) {\displaystyle R(\theta )} . Thus the clockwise rotation matrix is found as (by replacing θ with -θ and using the trigonometric symmetry of sin ( − θ ) = − sin ( θ ) {\textstyle \sin(-\theta )=-\sin(\theta )} and cos ( − θ ) = cos ( θ ) {\textstyle \cos(-\theta )=\cos(\theta )} )
R ( − θ ) = [ cos θ sin θ − sin θ cos θ ] . {\displaystyle 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 x-axis to the right and the y-axis up, the rotation R(θ) is counterclockwise. If a left-handed Cartesian coordinate system is used, with x directed to the right but y directed down, R(θ) 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 y-axis 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
[ 1 0 0 1 ] , [ 0 − 1 1 0 ] , [ − 1 0 0 − 1 ] , [ 0 1 − 1 0 ] {\displaystyle {\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
[ x − y y x ] {\displaystyle {\begin{bmatrix}x&-y\\y&x\end{bmatrix}}} form a ring, since their set is closed under addition and multiplication. Since
[ 0 − 1 1 0 ] 2 = [ − 1 0 0 − 1 ] = − I {\displaystyle {\begin{bmatrix}0&-1\\1&0\end{bmatrix}}^{2}\ =\ {\begin{bmatrix}-1&0\\0&-1\end{bmatrix}}\ =-I}
(where I {\textstyle I} is the identity matrix), the map
[ x − y y x ] = x [ 1 0 0 1 ] + y [ 0 − 1 1 0 ] ↦ x + i y {\displaystyle {\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 [ 0 − 1 1 0 ] {\displaystyle {\begin{bmatrix}0&-1\\1&0\end{bmatrix}}} corresponds to i {\displaystyle i} ) is a ring isomorphism from this ring to the field of the complex numbers C {\displaystyle \mathbb {C} } (incidentally, this shows that this ring is a field). Under this isomorphism, the rotation matrices [ cos t − sin t sin t cos t ] = cos t [ 1 0 0 1 ] + sin t [ 0 − 1 1 0 ] {\displaystyle {\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 1, since cos t 2 + sin t 2 = 1 {\displaystyle \cos t^{2}+\sin t^{2}=1} . As a result, the following equality holds, e i t = cos t + i sin t = cos t [ 1 0 0 1 ] + sin t [ 0 − 1 1 0 ] = ( cos t − sin t sin t cos t ) {\displaystyle 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 = [ 1 0 0 1 ] {\displaystyle I={\begin{bmatrix}1&0\\0&1\end{bmatrix}}} corresponds to 1, and the matrix [ 0 − 1 1 0 ] {\displaystyle {\begin{bmatrix}0&-1\\1&0\end{bmatrix}}} corresponds to the imaginary unit i {\textstyle i} . If one identifies R 2 {\displaystyle \mathbb {R} ^{2}} with C {\displaystyle \mathbb {C} } through the linear isomorphism ( a , b ) ↦ a + i b {\displaystyle (a,b)\mapsto a+ib} , where ( a , b ) ∈ R 2 {\displaystyle (a,b)\in \mathbb {R} ^{2}} and a + i b ∈ C {\displaystyle a+ib\in \mathbb {C} } , the action of a matrix [ x − y y x ] {\displaystyle {\begin{bmatrix}x&-y\\y&x\end{bmatrix}}} on a vector ( a , b ) {\displaystyle (a,b)} corresponds to multiplication on the complex number a + i b {\displaystyle a+ib} by x + iy. 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 1 (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 x-, y-, or z-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 ⋅ x → {\displaystyle R\cdot {\vec {x}}} . The same matrices can also represent a clockwise rotation of the axes keeping the vectors unchanged.
R x ( θ ) = [ 1 0 0 0 cos θ − sin θ 0 sin θ cos θ ] R y ( θ ) = [ cos θ 0 sin θ 0 1 0 − sin θ 0 cos θ ] R z ( θ ) = [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] {\displaystyle {\begin{alignedat}{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{alignedat}}}
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. Rz, for instance, would rotate toward the y-axis a vector aligned with the x-axis, as can easily be checked by operating with Rz on the vector (1,0,0):
R z ( 90 ∘ ) [ 1 0 0 ] = [ cos 90 ∘ − sin 90 ∘ 0 sin 90 ∘ cos 90 ∘ 0 0 0 1 ] [ 1 0 0 ] = [ 0 − 1 0 1 0 0 0 0 1 ] [ 1 0 0 ] = [ 0 1 0 ] {\displaystyle 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
R =
