#### Archived

This topic is now archived and is closed to further replies.

# Problem: Combined Rotation Matrix

This topic is 5898 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi... I''m having some problems with this equation for rotation by Lithium... Xv = x(s1s2s3 + c1c3) + y(c2s3) + z(c1s2s3 - c3s1) Yv = x(c3s1s2 - c1s3) + y(c2c3) + z(c1c3s2 + s1s3) Zv = x(c1s2s3 - c3s1) + y(-s2) + z(c1c2) Now I can get the X and Z axis to rotate fine... but when I try rotating the Y axis using this equation it just goes flying off... I''ve looked over and tested my matrix code and operators and they are all working... please note I have a matrix that is filled with only part of the equation... eg. |(s1s2s3 + c1c3) (c2s3) (c1s2s3 - c3s1) 0 | |(c3s1s2 - c1s3) (c2c3) (c1c3s2 + s1s3) 0 | |(c1s2s3 - c3s1) (-s2) (c1c2) 0 | | 0 0 0 1 | then to get the rotation point I multiply this matrix with a 4x1 vector (X,Y,Z,1). which ends up being the original equation... like I said this works for the X and Z axis... but not the Y.. its makes the point fly-off the screen. any Idea''s or does anyone have a better combined rotation matrix equation? thanks

##### Share on other sites
Maybe you will have to turn around all sings of the ''si'', or you''re happy with my turning direction. Note that this matrix is not in the DX notation with y (2nd) pointing up, but with z pointing up. But that should be done by swapping 2nd and 3rd column
[c3*c2   s3*c1 + c3*s2*s1  s3*s1 - c3*s2*c1  0][-s3*c2  c3*c1 - s3*s2*s1  c3*s1 + s3*s2*c1  0][s2      -c2*s1            c2*c1             0][0       0                 0                 1]

---------------------------
I may be getting older, but I refuse to grow up

##### Share on other sites
THANK YOU!.... hehe.... works like a charm... I do have one question... what units of mesurement do I need to use... at the moment say I want to rotate my 90 degree''s I have a vector (90,0,0) and then to calculate the cos and sin values I do

float c1 = cos(float((PI/180)*rot.x));

and that works to a degree.. but there seems to be a minute varation for some reason... eg... if I rotate by 1 degree 360 times its comes back to its original location a tad off.... I''ll need to double check this but it does seem so...

thanks for your equation btw... looking for that for ages... do you know any web pages that explain how you merge the three rotation matrix together... I would prefer to fully understand ''what'' is going on rather than just using the equation...

Thanks again

CrAKiN-ShOt

##### Share on other sites
forget the last problem... its fine now... I converted all var''s to doubles instead of floats and its rotating perfectly now...

##### Share on other sites
quote:
Original post by crakinshot
do you know any web pages that explain how you merge the three rotation matrix together...

Well i'll give explaining it shot. Something else first. I'm doing normal matrix operations here. That means the vector you multiply with the matrix stand on the right side of the matrix and is a column vector. DX and OGL do it the other way round.
v' = M * v

The rotation matrix above is an example of an valid 'M'.

Slight change of topic: The 3 rotation matrices.
Before I show you how to combine (i.e multiply) matrices I want to show you what you're combining. The three matrices, one for each axis, are pretty straight forward. Again, never mind the sign of the 'sin' as long as there are two different. Note that the axis of rotation always stays fixed.
Rotation about X    [ 1  0  0  0 ][ 0  c  s  0 ]  = Rx[ 0 -s  c  0 ][ 0  0  0  1 ]Rotation about Y    [ c  0 -s  0 ][ 0  1  0  0 ]  = Ry[ s  0  c  0 ][ 0  0  0  1 ]Rotation about Z    [ c -s  0  0 ][ s  c  0  0 ]  = Rz[ 0  0  1  0 ][ 0  0  0  1 ]

What the matrix I gave you does, is to apply first Rx than Ry and finally Rz to your vector. Writing this as a formula, all you have to keep in mind that you write your matrices down so that the matrix applied first is closest to the vector.
v' = Rz * Ry * Rx * v

This is definitely not the same as
v' = Rx * Ry * Rz * v

So how do you combine Rz * Ry * Rx into M? Matrix multiplication!
Each component of M has to be calculated individually. All 16.
Each component is the dot product of vectors. The position of the component to be caluculated is a line and a row. Take the line of the left matrix and the column of the right matrix to be multiplied, do the dot product and the result is the component with the said line the column.
With '#' being the values used to create '*'
[ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ][ #  #  #  # ]  *  [ .  #  .  . ]  =  [ .  *  .  . ][ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ][ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ]

This way you can combine two matrices. The two matrices have to be standing next to each other, and you may not reverse their order. But it doesn't matter if you first multiply Rz * Ry and the result with Rx or if you first multiply Ry * Rx and then multiply with Rz. Either M = (Rz * Ry) * Rx or M = Rz * (Ry * Rx)

Don't get frustrated if the first tries to recreate the result I gave you fail. Our professor took about a week explaining matrix multiplication (including some rules you don't need here) which is awfully long compared to the pace he took elsewhere.

[Edit: Format and Typos]

---------------------------
I may be getting older, but I refuse to grow up

[edited by - Dreamforger on August 1, 2002 10:18:52 PM]

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007539
• ### Who's Online (See full list)

There are no registered users currently online

×