Given an angle in radians, how could I calculate a 4x4 rotation matrix about the x, y, z axes?

6.7k Views Asked by At

My linear algebra skills are rusty. I need to write a bunch of computer code to do some matrix operations. For the most part, I've succeeded in doing things on my own, but I'm stuck with one operation.

Given an angle in radians, how could I calculate a 4x4 rotation matrix about the x, y, z axes? I need three matrices.

2

There are 2 best solutions below

0
On

this: http://www.fastgraph.com/makegames/3drotation/

is probably what you're talking about.

But if you're talking about a rotation about the three axes; then these are what you want:

$$X = \left(\begin{matrix} 1 & 0 & 0 \\ 0 & \cos(\theta) & -\sin(\theta) \\ 0 & \sin(\theta) & \cos(\theta)\end{matrix}\right)$$

$$Y = \left(\begin{matrix} \cos(\phi) & 0 & \sin(\phi) \\ 0 & 1 & 0 \\ -\sin(\phi) & 0 & \cos(\phi)\end{matrix}\right)$$

$$Z = \left(\begin{matrix} \cos(\psi) & -\sin(\psi) & 0 \\ \sin(\psi) & \cos(\psi) & 0 \\ 0 & 0 & 1\end{matrix}\right)$$

you just need to multiply them together in the correct order (i.e. reverse of the order which you perform them.

i.e. Rotation about X then Y then Z, or $$R_{xyz}(\theta,\phi,\psi) = R_z R_y R_x$$

which gives you this guy:

$$R_{xyz} = \left( \begin{matrix} \cos(\phi)\cos(\psi) & \cos(\psi)\sin(\theta)\sin(\phi)-\cos(\theta)\sin(\psi) & \cos(\theta)\cos(\psi)\sin(\phi)+\sin(\theta)\sin(\psi) \\ \cos(\phi)\sin(\psi) & \cos(\theta)\cos(\psi)+\sin(\theta)\sin(\phi)\sin(\psi) & \cos(\theta)\sin(\phi)\sin(\psi)-\cos(\psi)\sin(\theta) \\ -\sin(\phi) & \cos(\phi)\sin(\theta) & \cos(\theta)\cos(\phi)\\ \end{matrix}\right)$$

1
On

I suppose you are working in homogeneous coordinates to maintain any translation information. If not, this is probably not that helpful.

If you define $T$ to be the matrix which translates the point $p$ to the origin;$$T=\begin{bmatrix}I_3&-p\\ 0^T&1\end{bmatrix},$$ $T^{-1}$ as the matrix which translates the origin to point $p$;$$T^{-1}=\begin{bmatrix}I_3&p\\ 0^T&1\end{bmatrix}$$ and $R_H$ as the rotation matrix in homogeneous coordinates and $R$ as the $3\times3$ rotation, defined as here.$$R_H=\begin{bmatrix}R&0\\ 0^T&1\end{bmatrix}.$$

The matrix which then rotates about the point $p$ is then given by $T^{-1}R_HT$.