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!


1 Answer 1


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
  • \$\begingroup\$ 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. \$\endgroup\$
    – Lærne
    Apr 15, 2014 at 5:43
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Apr 15, 2014 at 13:17
  • \$\begingroup\$ @Steve, where you considering improving this answer based on the suggestions in the comments? \$\endgroup\$
    – House
    Apr 16, 2014 at 4:32
  • \$\begingroup\$ 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. \$\endgroup\$
    – Steve H
    Apr 16, 2014 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .