Celestial Programming : Rotation Matrices

A rotation matrix rotates a point (or vector) by a given angle around the origin. For a 3D rotation, there are three degrees of freedom, so a different matrix is needed for a rotation around each axis. But, for a 2D rotation, the only rotation which leaves the points in the original plane is a rotation about the (imagined) Z axis.

2D Rotation

$$ R{\bf v} = \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} $$


3D Rotation

$$ {\bf v} = \begin{bmatrix} x\\ y\\ z \end{bmatrix} $$ $$ R_x(\theta)= \begin{bmatrix} 1 & 0 & 0\\ 0 & \cos\theta & -\sin\theta\\ 0 & \sin\theta & \cos\theta\\ \end{bmatrix} $$ $$ R_y(\theta)= \begin{bmatrix} \cos\theta & 0 & \sin\theta\\ 0 & 1 & 0\\ -\sin\theta & 0 & \cos\theta\\ \end{bmatrix} $$ $$ R_z(\theta)= \begin{bmatrix} \cos\theta & -\sin\theta & 0\\ \sin\theta & \cos\theta & 0\\ 0 & 0 & 1\\ \end{bmatrix} $$