Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

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

How would I create a rotation matrix that rotates X by a, Y by b, and Z by c?

I need to formulas, unless you're using the ardor3d api's functions/methods.

Matrix is set up like this

xx, xy, xz,
yx, yy, yz,
zx, zy, zz

A Quaternion is fine too.

share|cite|improve this question
up vote 4 down vote accepted

The rotation matrices around the x, y, and z axes, respectively, are $$R_x(\theta) = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{pmatrix}$$ $$R_y(\phi) = \begin{pmatrix} \cos \phi & 0 & \sin \phi \\ 0 & 1 & 0 \\ - \sin \phi & 0 & \cos \phi \end{pmatrix}$$ $$R_z(\psi) = \begin{pmatrix} \cos \psi & - \sin \psi & 0 \\ \sin \psi & \cos \psi & 0 \\ 0 & 0 & 1 \end{pmatrix}$$

If you want to rotate in the order specified in your comment on mathcast's answer, then you want $$R_z(\psi) \cdot R_y(\phi) \cdot R_x(\theta) = $$

$$\begin{pmatrix} \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{pmatrix}$$

share|cite|improve this answer
I don't want to rotate it. I want to figure out how much it's rotated on each axis. – CyanPrime Dec 7 '10 at 1:51
@CyanPrime: Please update the OP to clarify exactly what you are asking for. You asked for a rotation matrix for the purpose of rotating... – Brandon Carter Dec 7 '10 at 2:39
Oh, sorry. wrong question. This answer is fine. Thank you very much ^^; – CyanPrime Dec 7 '10 at 3:04

I think that 3d rotation is more complicated than this; rotating around each of the axes separately can give different cumulative results depending on the order in which you choose to do the rotations.

see also

share|cite|improve this answer
I think the order is X, than Y, than Z – CyanPrime Dec 6 '10 at 19:10
@Cyan: there isn't a canonical order of "rotate with respect to this axis first", but certainly, you have a different set of matrices for each choice of order! – J. M. Dec 7 '10 at 0: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.