Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
I don't understand. Do you want to rotate in $4$-dimensional space? If so, "rotation about an axis" has no meaning. If not, what do you mean by a $4\times4$ rotation matrix? Perhaps you mean a matrix for an affine transformation, which includes both rotations and translations? That can be written using a $4\times4$ matrix. – joriki Oct 12 '11 at 15:18
I am not sure about what I need to do yet, but I think "Perhaps you mean a matrix for an affine transformation, which includes both rotations and translations? That can be written using a 4×4 matrix." is what I need. The matrix at the end of the calculation(s) must be 4x4. – Mark13426 Oct 12 '11 at 15:23
Well, it's a bit hard to help you if you don't know what it is you need to do :-). Perhaps take a look at this: Does that look useful? – joriki Oct 12 '11 at 15:25
I need "the rotation matrix (a 4x4 matrix) about the x,y,z axes respectively by the specified angle in radians" Does that make sense? :) – Mark13426 Oct 12 '11 at 15:25
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. – joriki Oct 12 '11 at 15:31


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

share|cite|improve this answer

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

share|cite|improve this answer
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. – Lubin Sep 1 '12 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.