Sign in to follow this  

Matrix Question

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a matrix with translation (A) and one with rotation (B). I need to rotate the coordinates of matrix A using matrix B around the origin. The problem is when I do (A)*(B) the top left 3x3 part of matrix A changes but (0,3), (1,3), and (2,3) don't. It seems like the matrix rotates but not around the origin. How do I do this? Using CML by the way.

Share this post


Link to post
Share on other sites
Try B * A

Depending on how you arrange your matrices, (A) * (B) could be read "first A, then B" or "first B, then A" [since different implementations use different matrix arrangements]. What you're describing A * B to be is 'translate first, then rotate'. What you're looking for is 'rotate first, then translate'.

Generally the two implementations differ with how they are applied to a vector, and can be read as such. V2 = V1 * M would be read left-to-right. V2 = M * V1 is also correct, and is read right to left. The actual matrices in these two equations are not equal, nor are they constructed equally [matter of a fact, they are transposes]. But your convention will decide whether you represent vectors as rows or columns, which will imply how you represent your matrices. In either implementation, one of these should be 'correct', and the other should be completely illegal.

The misunderstanding that is occuring in your example is using the matrices that are constructed to be used left-to-right, put together from right-to-left [thus, backwards]

Share this post


Link to post
Share on other sites
Quote:
Original post by Gumgo
I have a matrix with translation (A) and one with rotation (B). I need to rotate the coordinates of matrix A using matrix B around the origin. The problem is when I do (A)*(B) the top left 3x3 part of matrix A changes but (0,3), (1,3), and (2,3) don't. It seems like the matrix rotates but not around the origin.



How do I do this?

Using CML by the way.
I gather from what you've posted that you're using column-vector notation (in CML terms, this would imply the use of e.g. cml::matrix44f_c).

With column-vector notation, the transforms represented by the matrices in a matrix expression such as A*B are applied in order from right to left. In you case, this means that the object is being rotated, then translated, leading to the results in your third image. (This also correlates to what you describe - that the translation component of the matrix product A*B is the same as that of matrix A).

Judging by your fourth image, it looks like you want to translate, then rotate; in other words, you want B*A, not A*B.

[Edit: What Drigovas said.]

Share this post


Link to post
Share on other sites
Quote:
What you're describing A * B to be is 'translate first, then rotate'. What you're looking for is 'rotate first, then translate'.
Actually, I think it's 'translate first, then rotate' that he wants, and 'rotate first, then translate' that he's getting.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
What you're describing A * B to be is 'translate first, then rotate'. What you're looking for is 'rotate first, then translate'.
Actually, I think it's 'translate first, then rotate' that he wants, and 'rotate first, then translate' that he's getting.
Whoops, thanks for catching it. Sorry.

Right you are....Sometimes I get to typing, and... well, you see.

[Edited by - Drigovas on September 16, 2007 6:42:42 PM]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this