Take the 2-minute tour ×
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.

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|improve this question

2 Answers 2

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

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

share|improve this answer
    
I think the order is X, than Y, than Z –  CyanPrime Dec 6 '10 at 19:10
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! –  J. M. Dec 7 '10 at 0:02

Your Answer

 
discard

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.