# Relative Position/Rotation calculation

I have 2 objects each with a 3x3 Matrix (Orientation) and a Vector3 (Translation). Both are relative to world coordinates.

How do I calculate the position and orientation of object B in relation to object A?

I'm using the JVector, JMatrix that are a part of the Jitter3D physics library. (http://code.google.com/p/jitterphysics/)

Any help would be greatly appreciated!

For the matrix, you multiply them to combine rotations:

so if using row Major matrices:

someUnknownRotationMatrix * OrientationA  = OrientationB


then: someUnknownRotation represents the orientation of object B in relation to object A

so, using basic math principles (divide both sides by OrientationA):

someUnknownMatrix = MatrixB * inverse(MatrixA)


## -

Similar with the position:

Vector3 someUnknownVector;//represents position of object B in relation to object A

positionA + someUnknownVector = positionB
//then after applying similar math principles(subtract positionA from both sides):
someUnknownVector = positionB - positionA

• Matrix product is not commutative in general, if you want to divide the left hand-side of a product, you must divide by the left: someUnknownMatrix = inverse(OrientationA) * OrientationB. I'm fully aware in the case of rotation matrices, it is commutative, but let's take the good habits. From that perspective, I would also use someUnknownRotationMatrix * OrientationA = OrientationB as the basic equation and divide on the right. – Lærne Apr 15 '14 at 5:43
• Almost everything is wrong in here. All lines mentioning someUnknownMatrix have the wrong multiplication order, and one even inverts the wrong matrix. And the last part ignores the impact the rotation has on the relative translation. – sam hocevar Apr 15 '14 at 13:17
• @Steve, where you considering improving this answer based on the suggestions in the comments? – MichaelHouse Apr 16 '14 at 4:32
• I've edited my answer be reversing the order of multiply in the 1st snippet and by removing the note about column major matrices which I assumed was correct but can not test. Here is what I used to test this edit before correcting it: pastebin.com/b7awPZRY This was in Xna. As far as the position comment by sam, I interpreted the positions to be independent of the matrices due to the OP's first sentence that they were in world space. If I have missed the intent of this question, please feel free to let me know and delete my answer if necessary. – Steve H Apr 16 '14 at 12:25