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

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.

-

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

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