({{, (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ] 
gives the 2D rotation matrix that rotates 2D vectors counterclockwise by θ radians.}, {, (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,w]
gives the 3D rotation matrix for a counterclockwise rotation around the 3D vector w.}, {, (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[{u,v}]
gives the matrix that rotates the vector u to the direction of the vector v in any dimension.}, {, (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{u,v}]
gives the matrix that rotates by θ radians in the plane spanned by u and v.}})

OpenersNotesSection(Spacer1)Details

(RefLink[RotationMatrix, paclet:ref/RotationMatrix]) gives matrices for rotations of vectors around the origin.

Two different conventions for rotation matrices are in common use.

(RefLink[RotationMatrix, paclet:ref/RotationMatrix]) is set up to use the vector-oriented convention and to give a matrix m so that m.r yields the rotated version of a vector r.

(RefLink[Transpose, paclet:ref/Transpose])[RotationMatrix[…]] gives rotation matrices with the alternative coordinate-system-oriented convention for which r.m yields the rotated version of a vector r.

Angles in (RefLink[RotationMatrix, paclet:ref/RotationMatrix]) are in radians. θ (RefLink[Degree, paclet:ref/Degree]) or θ° specifies an angle in degrees.

Positive θ in (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{u,v}] corresponds to going from the direction of u towards the direction of v.

(RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ] is equivalent to (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{{1,0},{0,1}}].

(RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,w] is equivalent to (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{u,v}], where u⊥w, v⊥w, and u,v,w form a right-handed coordinate system.

(RefLink[RotationMatrix, paclet:ref/RotationMatrix]) gives an orthogonal matrix of determinant 1, that in n dimensions can be considered an element of the group SO (n).

OpenersPrimaryExamplesSection(Spacer1)Examples  (23)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

General 2D rotation matrix for rotating a vector about the origin:

RotationMatrix[θ]//MatrixForm

Apply rotation by θ to a unit vector in the x direction:

RotationMatrix[θ].{1,0}

Counterclockwise rotation by 30°:

RotationMatrix[30Degree]

Rotation that transforms the direction of {1,1} into the direction of {0,–1}:

RotationMatrix[{{1,1}, {0,-1}}]

3D rotation around the z axis:

RotationMatrix[θ,{0,0,1}]//MatrixForm

OpenersExampleSection1(Spacer1)Scope  (6)

A 4D rotation matrix, rotating in the x y plane:

RotationMatrix[θ, {{1,0,0,0}, {0,1,0,0}} ]//MatrixForm

A general 3D rotation matrix, rotating in the plane given by t{1,1,1} + s{1,–2,1}:

RotationMatrix[θ, {{1,1, 1},{1,-2,1}}]//Simplify//MatrixForm

Rotate the vector {1,0,0} to the vector {0,0,1}:

r = RotationMatrix[ {{1,0,0}, {0,0,1}}]

r.{1,0,0}

Generate the rotation matrix for symbolic vectors, assuming that all quantities are real:

ComplexExpand[RotationMatrix[{{0,0,1},{x,y,z}}],TargetFunctions->{Re,Im}]//Simplify

Rotating {0,0,1} gives the normalized {x,y,z} vector:

%.{0,0,1}

Transformation applied to a 2D shape:

gr={Rectangle[],AbsolutePointSize[10],Opacity[1],{Magenta,Point[{0,0}]},{Green,Point[{1,1}]}};

Graphics[{{Opacity[.35],Blue,gr},GeometricTransformation[{Opacity[.85],Red,gr},RotationMatrix[-2Pi/3]]}]

Transformation applied to a 3D shape:

gr={Cuboid[],AbsolutePointSize[10],Opacity[1],{Magenta,Point[{0,0,0}]},{Green,Point[{1,1,1}]}};

Graphics3D[{{Opacity[.35],Blue,gr},GeometricTransformation[{Opacity[.85],Red,gr},RotationMatrix[-2Pi/3,{0,0,1}]]},Boxed->False]

OpenersExampleSection3(Spacer1)Applications  (2)

Rotating 3D shapes:

Graphics3D[{{Opacity[.5],Cuboid[{-.5,-.5,-.5}]},GeometricTransformation[Cuboid[{-.5,-.5,-.5}],RotationMatrix[{{0,0,1},{1,-1,1}}]]},Boxed->False]

Produce a basis for all rotations in dimension n:

SO[n_]:=Map[RotationMatrix[θ,#]&,Subsets[Table[UnitVector[n,i],{i,n}], {2}]];

All rotations in 2D:

Map[MatrixForm,SO[2]]

All rotations in 3D:

Map[MatrixForm,SO[3]]

All rotations in 4D; in general n(n-1)/2 basis elements are needed for dimension n:

Map[MatrixForm,SO[4]]

OpenersExampleSection4(Spacer1)Properties & Relations  (9)

A rotation matrix is orthogonal, i.e. the inverse is equal to the transpose:

r=RotationMatrix[θ]

Inverse[r]-Transpose[r]//Simplify

In the complex case, the rotation matrix is unitary:

RotationMatrix[{{1+I,1-I},{-2I,1-3I}}].ConjugateTranspose[RotationMatrix[{{1+I,1-I},{-2I,1-3I}}]]

A rotation matrix has determinant +1:

Det[RotationMatrix[θ]]//Simplify

Multiplying by the rotation matrix preserves the norm of a vector:

Norm[RotationMatrix[{{1+I,1-I},{-2I,1-3I}}].{-2-2I,3+I}]==Norm[{-2-2I,3+I}]//Simplify

The inverse of (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{u,v}] is given by (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[-θ,{u,v}]:

RotationMatrix[θ,{{1,0,0}, {0,0,1}}].RotationMatrix[-θ,{{1,0,0}, {0,0,1}}]//Simplify

The inverse of (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{u,v}] is also given by (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,{v,u}]:

RotationMatrix[θ,{{1,0,0}, {0,0,1}}].RotationMatrix[θ,{{0,0,1},{1,0,0}}]//Simplify

If u or v is not real the relationship is more complex:

RotationMatrix[Pi/3,{{1,0,1}, {1+I,0,1}}].RotationMatrix[Pi/3,{{1+I,0,1},{1,0,1}}]//Simplify

In 2D the inverse of (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ] is given by (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[-θ]:

RotationMatrix[θ].RotationMatrix[-θ]//Simplify

In 3D the inverse of (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,w] is given by (RefLink[RotationMatrix, paclet:ref/RotationMatrix])[θ,-w]:

RotationMatrix[θ,{0,0,1}].RotationMatrix[θ,-{0,0,1}]//Simplify

If w is not real the relationship is more complex:

RotationMatrix[θ,{1+I,1-I,0}].RotationMatrix[θ,-{1+I,1-I,0}]//Simplify

The composition of rotations is a rotation:

MatrixPower[RotationMatrix[a],n]-RotationMatrix[n a]//FullSimplify[#,Element[n,Integers]&&Element[a,Reals]]&

OpenersExampleSection5(Spacer1)Possible Issues  (1)

The order in which rotations are performed is important:

rx = RotationMatrix[θ,{1,0,0}];
ry = RotationMatrix[ϕ,{0,1,0}];

Rotating around x and then y is not the same as first rotating around y and then x:

rx.ry-ry.rx

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Rotations of a circular sector:

Graphics[Table[GeometricTransformation[Disk[{2,0},1,{-7Pi/10,7Pi/10}],RotationMatrix[a]],{a,2Pi/5Range[5]}],PlotRange->3.1]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RotationTransform, paclet:ref/RotationTransform])  ▪  (RefLink[EulerMatrix, paclet:ref/EulerMatrix])  ▪  (RefLink[RollPitchYawMatrix, paclet:ref/RollPitchYawMatrix])  ▪  (RefLink[Rotate, paclet:ref/Rotate])  ▪  (RefLink[Dot, paclet:ref/Dot])  ▪  (RefLink[UnitVector, paclet:ref/UnitVector])  ▪  (RefLink[Sin, paclet:ref/Sin])  ▪  (RefLink[ReflectionMatrix, paclet:ref/ReflectionMatrix])  ▪  (RefLink[ScalingMatrix, paclet:ref/ScalingMatrix])  ▪  (RefLink[PauliMatrix, paclet:ref/PauliMatrix])  ▪  (RefLink[AnglePath3D, paclet:ref/AnglePath3D])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Constructing Matrices, paclet:tutorial/ConstructingMatrices])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Geometric Transforms, paclet:guide/GeometricTransforms])}, {▪(RefLinkPlain[Constructing Matrices, paclet:guide/ConstructingMatrices])}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}, {▪(RefLinkPlain[Angles and Polar Coordinates, paclet:guide/AnglesAndPolarCoordinates])}})}})