Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'd like to know how to get the rotation matrix for the transformation from one cartesian coordinate system (X,Y,Z) to another one (X',Y',Z'). Both systems are defined with three orthogonal vectors as one would expect. No scaling or translation occurs. I'm using OpenSceneGraph and it offers a Matrix convenience class, if it makes finding the matrix easier: http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00403.html.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

One easy way is to think of both coordinate systems as transforms from the unit vectors (1,0,0) (0,1,0) and (0,0,1). You start off in this coordinate space (I will call it '1')whose transform matrix is the identity matrix:

    [1,0,0]
I = [0,1,0]
    [0,0,1]

then your first coordinate space (I will call it '2') has the transform matrix:

    [Xx,Xy,Xz]
A = [Yx,Yy,Yz]
    [Zx,Zy,Zz]

and your second coordinate space (I will call it '3') has the transform matrix:

    [Xx',Xy',Xz']
B = [Yx',Yy',Yz']
    [Zx',Zy',Zz']

For your points to be in the first coordinate system, then you have transformed them from 1 to 2. If you want to go from 2 to 3 then you can undo the transform from 1 to 2 then do the transform from 1 to 3. You can reverse the transform by inverting 2's transform matrix.

A point v in 2 can be transformed to a point v' in 3 with this equation: v' = B(A^-1)v where (A^-1) is the inverse of A.

Note this also handles scaling even though you don't need it. This approach will work with translation as well, though you would need a 4x4 matrix instead of a 3x3.

share|improve this answer
    
Hey, thank you for the great answer. I wanted to clarify a couple of things though. v'=(A^-1)v takes me from CS2->CS1. Then v'' = Bv' would take me from CS1->CS3, or you can compactly write CS2->CS3 as v'=B(A^-1)v as you did. Also in my case, CS2 == CS1, so all I'd have to do to get to CS3 is v'=Bv ... is that correct? –  Pris Mar 24 '12 at 15:10
    
That is indeed correct. You can multiply matrices to combine their transformations, so if you have lots of points its more efficient to multiply B(A^-1) once and used that. –  Chewy Gumball Mar 24 '12 at 17:42
    
Can I ask a further question about this problem... I understand the answer given but can't work out how calculate the transforms [A] or [B] for my situation. I have one vector shown in the two coordinate systems '2' and '3', so how can I calculate the transforms [A] and [B]. eg. v = [0.5; 5; 3] and v' = [1; 5.408; 2] Any clues –  user26395 Feb 16 '13 at 18:46
    
That is a difficult question. If you have only one vector, you can find the rotation from the x-axis then scale the magnitude to match (see gamedev.stackexchange.com/questions/6137/…), but in general, this is a difficult problem, especially when you have sources of error. –  Chewy Gumball Feb 17 '13 at 19:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.