Calculate relative rotation matrix

Started by
4 comments, last by Hodgman 10 years, 1 month ago

Hello,

I have 2 objects both with their own 3x3 orientation matrix.

I need to calculate the orientation of object B in relation to object A.

Thanks in advance!

Advertisement

A,inverse() * B?

I think.

Everything is better with Metal.

One thing that helps in these situations is to think of the poses of your objects as relative transformations with respect to a privileged coordinate frame. In this case, I will rename the two rotations for your objects as such:

R_wa -- The 3x3 rotation matrix of object A in the world frame (or a transformation from the coordinate frame of A to the world coordinate frame)

R_wb -- The 3x3 rotation matrix of object B in the world frame (or a transformation from the coordinate frame of B to the world coordinate frame)

With this notation, if any transformations are multiplied together, the inner indices will cancel. What you've asked for is the rotation of object B in the frame of object A. Given my previous nomenclature, this is written as

R_ab

So how do we get to this? We do the multiplication as described before, canceling the inner indices:

R_ab = R_aw * R_wb

Since you only have R_wa, you need to invert it to get R_aw. However, being an orthogonal rotation matrix, its inverse is its transpose R_wa'. So therefore:

R_ab = R_wa^-1 * R_wb = R_wa' * R_wb

Basically, what papalazaru said was right, but I wanted to outline a method where you'll never go wrong as long as you stick to this representation. If you replace the rotation matrix with a homogeneous 4x4 transformation matrix, the same principle will hold. Just remember that the inverse of the 4x4 matrix is not it's transpose, but there is an easy way to obtain it.

The above answers are correct in principle, but there is a caveat. The answers assume that column vectors are used. If the OP uses row vectors instead, then the order of the both matrices need to be reversed to what is shown above. Neglecting the normally needed transposes, things look as follows:

Column vectors:

MB * vB = MA * vA <=> MA-1 * MB * vB = MA-1 * MA * vA <=> MA-1 * MB * vB = vA <-- the solution shown above

Row vectors:

vB * MB = vA * MA <=> vB * MB * MA-1 = vA * MA * MA-1 <=> vB * MB * MA-1 = vA <-- notice the reverse order of matrices compared to other solution

Haegar, I'm not sure what you mean by 'row vectors' . Do you mean to say that the rotation matrix's rows are swapped with its columns? In that case that is just the transpose or inverse rotation. As far as I am aware, the orthogonal rotation matrix is composed of three basis vectors, represented as the three unit-length columns of the rotation matrix. Whether you use row-major or column-major storage does not change the mathematical representation, as your multiplication routine should handle the proper row/column ordering.

When you multiply vectors and matrices, the N-dimensional vector either becomes a 1-row by N-column matrix (a "row vector"), or a N-row by 1-column matrix (a "column vector").
This is a difference is mathematical convention, completely separate from "row major" vs "column major" storage (a software engineering convention).

Mathematicians generally use column vectors, which as a by-product, results in you storing your basis vectors in the columns of your matrices for the math to work out correctly (which in-turn results in column-major storage being the optimal storage option).

However, some software systems, and some documentation on the net actually uses the opposite mathematical convention (of a vec4 being a mat1x4, not a mat4x1), which has a series of knock-on effects, including transposing the mathematical layout of your matrices (regardless of the storage convention used).

This topic is closed to new replies.

Advertisement