Problem: Combined Rotation Matrix

Started by
3 comments, last by crakinshot 21 years, 8 months ago
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
-=CrAKiN:ShOt=-I could put something witty here but I'm not that stupid...
Advertisement
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
I may be getting older, but I refuse to grow up
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

-=CrAKiN:ShOt=-I could put something witty here but I'm not that stupid...
forget the last problem... its fine now... I converted all var''s to doubles instead of floats and its rotating perfectly now...
-=CrAKiN:ShOt=-I could put something witty here but I'm not that stupid...
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<br>[ 0  0  0  1 ]<br><br><b>Rotation about Z  </b>  <br>[ c -s  0  0 ]<br>  = Rz<br>[ 0  0  1  0 ]<br>[ 0  0  0  1 ]  </pre>  <br><br>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.<pre>v' = Rz * Ry * Rx * v  </pre>  <br>This is definitely not the same as <pre>v' = Rx * Ry * Rz * v  </pre>  <br><br>So how do you combine Rz * Ry * Rx into M? Matrix multiplication!<br>Each component of M has to be calculated individually. All 16.<br>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. <br>With '#' being the values used to create '*'<br><pre><br>[ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ]<br>[ #  #  #  # ]  *  [ .  #  .  . ]  =  [ .  *  .  . ]<br>[ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ]<br>[ .  .  .  . ]     [ .  #  .  . ]     [ .  .  .  . ]<br>  </pre>  <br>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)<br><br>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. <br><br><br><br>[Edit: Format and Typos]    <br><br>—————————<br>I may be getting older, but I refuse to grow up<br><br><SPAN CLASS=editedby>[edited by - Dreamforger on August 1, 2002 10:18:52 PM]</SPAN>    
I may be getting older, but I refuse to grow up

This topic is closed to new replies.

Advertisement