2
$\begingroup$

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
    No, as I wrote, that doesn't make any sense. A rotation matrix about an axis is a $3\times3$ matrix. Even if you were dealing with $4$-dimensional space (which I suspect you aren't), it wouldn't make any sense, because in four dimensions rotations don't have an axis. Can you provide more context? The only sense I can make of it in this form is that someone presupposed the $4\times4$ matrix form for an affine transformation and called the corresponding matrix describing only a rotation a "rotation matrix". But if so, that should be clear from the context.2011-10-12

2 Answers 2

3

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)$

2

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$.

  • 0
    This is it, you have to represent a Euclidean transformation by a 4x4 matrix. I do wonder that your notation may be a bit too economical for the OP, but that’s for him to decide.2012-09-01