tags:

views:

75

answers:

3

Given the following definitions for x,y,z rotation matrices, how do I represent this as one complete matrix? Simply multiply x, y, & matrices?

X Rotation:

[1 0 0 0]
[0 cos(-X Angle) -sin(-X Angle) 0]
[0 sin(-X Angle) cos(-X Angle) 0]
[0 0 0 1]

Y Rotation:

[cos(-Y Angle) 0 sin(-Y Angle) 0]
[0 1 0 0]
[-sin(-Y Angle) 0 cos(-Y Angle) 0]
[0 0 0 1]

Z Rotation:

[cos(-Z Angle) -sin(-Z Angle) 0 0]
[sin(-Z Angle) cos(-Z Angle) 0 0]
[0 0 1 0]
[0 0 0 1] 

Edit: I have a separate rotation class that contains an x, y, z float value, which I later convert to a matrix in order to combine with other translations / scales / rotations.

Judging from the answers here, I can assume that if I do something like:

Rotation rotation; rotation.SetX(45); rotation.SetY(90); rotation.SetZ(180);

Then it's actually really important as to which order the rotations are applied? Or is it safe to make the assumption that when using the rotation class, you accept that they are applied in x, y, z order?

+4  A: 

Yes, multiplying the three matrices in turn will compose them.

EDIT:

The order that you apply multiplication to the matrices will determine the order the rotations will be applied to the point.

P × (X × Y × Z)     Rotations in X, Y, then Z will be performed
P × (Y × X × Z)     Rotations in Y, X, then Z will be performed
P × (Z × X × Y)     Rotations in Z, X, then Y will be performed
Ignacio Vazquez-Abrams
Note though that it may or may not be the rotation that you're expecting (remember than in 3D, rotations do NOT commute.)
But note that the order of composition matters - matrix multiplication is not commutative, and neither are rotations about different axes.
walkytalky
First, decide which order to apply the rotations (say X then Y then Z). Then, it also depends on your convention of whether your points are row vectors or column vectors. For row vectors, you have `((r*X)*Y)*Z = r*(XYZ)` -- vs. column vectors, you have `Z*(Y*(X*c))=(ZYX)*c` .
comingstorm
I've updated my question, please could you clarify a little further?
Mark Ingram
A: 

As an aside and if you're early enough in your development activities here, you might want to consider using quaternion rotation. It has a number of comparative advantages to matrix based approaches.

andand
A: 

It actually is really important what order you apply your rotations in.

The order you want depends on what you want the rotations to do. For instance, if you are modeling an airplane, you might want to do the roll first (rotate along the long axis of the body), then the pitch (rotate along the other horizontal axis), then the heading (rotate along the vertical axis). This would be because, if you did the heading first, the plane would no longer be aligned along the other axes. Beyond that, you need to deal with your conventions: which of these axes correspond to X, Y, and Z?

Generally, you only want to choose a particular rotation order for specific applications. It doesn't make much sense to define a generic "XYZrotation" object; typically, you will have generic transformations (i.e., matrices that can be any concatenation of rotations, translations, etc.) and various ways to get them (e.g., rotX, rotY, translate, scale...), plus the ability to apply them in a particular order (by doing matrix multiplication).

If you want something that can only represent rotations and nothing else, you might consider quaternions (as anand suggests). However, you still need to decide which order to perform your rotations in, and, again, it doesn't really make sense to hardwire a required order for that.

comingstorm