Problem multiplying rotation matrices together

I am using this for a game, but I didn't put it in the game forum because more people view GD. Plus it's math oriented, therefore you don't have to be into game programming to possibly help me.

Anyway, from what I understand from OpenGL Game Programming you can multiply the Z axis rotation matrix by the Y axis rotation by the X axis rotation. It comes right out and says the final equations(the 'concatenation' of the three matrices), but I'm not exactly sure how they got there. I'm going to post the three matrices and then the final equations. Note the delta means the degrees travelled about that axis only. If I made any mistakes please point them out, it was a lot to copy. I tried making this as neat as possible, but the matrices keep being posted unaligned.

Z axis rotation matrix:

Code:

`cosDelta -sinDelta 0 0`

sinDelta cosDelta 0 0

0 0 1 0

0 0 0 1

Y axis rotation matrix;

Code:

`cosDelta 0 sinDelta 0`

0 1 0 0

-sinDelta 0 cosDelta 0

0 0 0 1

X axis rotation matrix:

Code:

`1 0 0 0`

0 cosDelta -sinDelta 0

0 sinDelta cosDelta 0

0 0 0 1

Here are the final equation describing how the X image, Y image and Z image are related to the concatenation of the 3 matrices above

X' = X[(cosZDelta) * (cosYDelta)] +

Y[cosZDelta) * (sinYDelta) * (sinXDelta) - (sinZDelta) *(cosXDelta] +

Z[(cosZDelta) *(sinYDelta) * (sinYDelta) - (sinZDelta) * (cosXDelta)]

Y' = X[(sinZDelta) * (cosYDelta)]+

Y[(sinZDelta) * (sinYDelta) * (sinXDelta) - (cosZDelta) * (cosXDelta)+

Z[(sinZDelta) *(sinYDelta) * (cosXDelta) - (cosZDelta) * (sinXDelta)]

Z' = -x*(sin?) + z*(cosYDelta)*(sinXDelta)]

I'm not sure if the question mark is a mistake from the book or not, unfortunately I suspect it is, but when I know what I'm doing I'll be able to figure out what it's supposed to be.

As I said I do not know how they multiplied the first three matrices together to get the final equations. I do know how to work with matrices, i.e the image matix will have the number of rows from the first matrix and the number of columns from the second matrix. I know how to multiply *two* matrices together (Matrix1Row[0][0] * Matrix2Column[0][0] add those together and continue until first column is filled). Anyay if anyone can shed some light onto what is going on I will be very happy.

Re: Problem multiplying rotation matrices together

Quote:

*Originally posted by Silvercord *
**I am using this for a game, but I didn't put it in the game forum because more people view GD. Plus it's math oriented, therefore you don't have to be into game programming to possibly help me.**

Anyway, from what I understand from OpenGL Game Programming you can multiply the Z axis rotation matrix by the Y axis rotation by the X axis rotation. It comes right out and says the final equations(the 'concatenation' of the three matrices), but I'm not exactly sure how they got there. I'm going to post the three matrices and then the final equations. Note the delta means the degrees travelled about that axis only. If I made any mistakes please point them out, it was a lot to copy. I tried making this as neat as possible, but the matrices keep being posted unaligned.

Z axis rotation matrix:

Code:

`cosDelta -sinDelta 0 0`

sinDelta cosDelta 0 0

0 0 1 0

0 0 0 1

Y axis rotation matrix;

Code:

`cosDelta 0 sinDelta 0`

0 1 0 0

-sinDelta 0 cosDelta 0

0 0 0 1

X axis rotation matrix:

Code:

`1 0 0 0`

0 cosDelta -sinDelta 0

0 sinDelta cosDelta 0

0 0 0 1

Here are the final equation describing how the X image, Y image and Z image are related to the concatenation of the 3 matrices above

X' = X[(cosZDelta) * (cosYDelta)] +

Y[cosZDelta) * (sinYDelta) * (sinXDelta) - (sinZDelta) *(cosXDelta] +

Z[(cosZDelta) *(sinYDelta) * (sinYDelta) - (sinZDelta) * (cosXDelta)]

Y' = X[(sinZDelta) * (cosYDelta)]+

Y[(sinZDelta) * (sinYDelta) * (sinXDelta) - (cosZDelta) * (cosXDelta)+

Z[(sinZDelta) *(sinYDelta) * (cosXDelta) - (cosZDelta) * (sinXDelta)]

Z' = -x*(sin?) + z*(cosYDelta)*(sinXDelta)]

I'm not sure if the question mark is a mistake from the book or not, unfortunately I suspect it is, but when I know what I'm doing I'll be able to figure out what it's supposed to be.

As I said I do not know how they multiplied the first three matrices together to get the final equations. I do know how to work with matrices, i.e the image matix will have the number of rows from the first matrix and the number of columns from the second matrix. I know how to multiply *two* matrices together (Matrix1Row[0][0] * Matrix2Column[0][0] add those together and continue until first column is filled). Anyay if anyone can shed some light onto what is going on I will be very happy.

Hi,

Remember that although matrix multiplication is not *commutative*, it is *associative*, so it doesn't matter which two matrices you multiply together first in the above example, as long as the overall order is kept.

So, you want to create a composite matrix, which has the effect of a rotation about Z, then a rotation about Y, then a rotation about X. Remember that the non-commutativity of matrix multiplication still stands with rotations; the fact that the result of combining rotations depends on the order in which you perform them is a geometric fact about rotations. It is easy to see that the non-commutativity of rotations is a geometric fact. Just hold a non-cubical rectangular box in your hands and try rotating it by 90 degrees successively about two different axes, note the resulting orientation, then return it to its original orientation and perform the same two rotations but in the opposite order. Therefore, we must multiply the three matrices (we will call them Z, Y and X respectively) in the order ZYX. But due to matrix associativity, it doesn't matter whether we evaluate ZY first or YX first. If you evaluate ZY first (call it P), then simply multiply that by X, (in the order PX) to get the final composite matrix. If you evaluate YX first (call it G), then simply multiply that by Z, (in the order ZG) to get the final composite matrix.

By the way, your definitions for each individual rotation matrix are correct, and I'm sure you can now mulitply them together as explained to check the last bit.

P.S. You've used 'delta' for your angle variable in all of the above rotations, I don't know whether or not you intended to do this, as it would obviously only allow a rotation of the same amount around each axis.

I hope this helps,

Regards,