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

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 :

If and are the coordinates of the endpoint of a vector with the length r and the angle with respect to the -axis, so that and , then the above equations become the trigonometric summation angle formulae: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:

This rotates column vectors by means of the following matrix multiplication,

Thus, the new coordinates of a point after rotation are

Examples For example, when the vector (initially aligned with the x-axis of the Cartesian coordinate system)

is rotated by an angle , its new coordinates are

and when the vector (initially aligned with the y-axis of the coordinate system)

is rotated by an angle , its new coordinates are

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 . Thus the clockwise rotation matrix is found as (by replacing with and using the trigonometric symmetry of and )

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

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 form a ring, since their set is closed under addition and multiplication. Since

(where is the identity matrix), the map

(where corresponds to ) 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 correspond to the circle of the unit complex numbers, the complex numbers of modulus , since . As a result, the following equality holds,where the first equality is Euler's formula, the matrix corresponds to 1, and the matrix corresponds to the imaginary unit .

If one identifies with through the linear isomorphism , where and , the action of a matrix on a vector corresponds to multiplication on the complex number 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 . The same matrices can also represent a clockwise rotation of the axes keeping the vectors unchanged.Note that if instead of rotating vectors, it is the reference frame that is being rotated, the signs on the terms will be reversed. If reference frame A is rotated anti-clockwise about the origin through an angle to create reference frame B, then (with the signs flipped) will transform a vector described in reference frame A coordinates to reference frame B coordinates. Coordinate frame transformations in aerospace, robotics, and other fields are often performed using this interpretation of the rotation matrix.

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 :

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

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

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

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

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:

Since is a skew-symmetric matrix, we can choose such that

The matrix–vector product becomes a cross product of a vector with itself, ensuring that the result is zero:

Therefore, if

then

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:

from which follows that the angle's absolute value is

For the rotation axis , you can get the correct anglefrom

where

Rotation matrix from axis and angle The matrix of a proper rotation by angle around the axis , a unit vector with , is given by:

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

where is the cross product matrix of ; the expression is the outer product, and is the identity matrix. Alternatively, the matrix entries are:

where is the Levi-Civita symbol with . This is a matrix form of Rodrigues' rotation formula, (or the equivalent, differently parametrized Euler–Rodrigues formula) withNote that

so that, in Rodrigues' notation, equivalently,

In the rotation of a vector around the axis by an angle can be written as:

or equivalently:

This can also be written in tensor notation as: