1
$\begingroup$

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.

2 Answers 2

4

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

  • 0
    I don't want to rotate it. I want to figure out how much it's rotated on each axis.2010-12-07
  • 1
    @CyanPrime: Please update the OP to clarify exactly what you are asking for. You asked for a rotation matrix for the purpose of rotating...2010-12-07
  • 0
    Oh, sorry. wrong question. This answer is fine. Thank you very much ^^;2010-12-07
4

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

http://en.wikipedia.org/wiki/Rotation_matrix#Three_dimensions

  • 0
    I think the order is X, than Y, than Z2010-12-06
  • 1
    @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!2010-12-07