Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change 'handedness' of a Row-major 4x4 transformation matrix

I have transformation and rotation coordinate data that is in a Row-major 4x4 transformation matrix format.

Ux Vx Wx Tx    
Uy Vy Wy Ty    
Uz Vz Wz Tz    
0  0  0  1

The source of the data and the software that I need to send it to have different handed coordinate systems. One is left-handed, the other right.

How can I change the matrix from right to left handed and vice versa? I understand that for transformations you can just invert the Y axis, but for rotations it seems more complex.

Thanks.

like image 464
anti Avatar asked May 14 '15 10:05

anti


People also ask

Why is a transformation matrix 4x4?

The 4 by 4 transformation matrix uses homogeneous coordinates, which allow to distinguish between points and vectors. Vectors have a direction and magnitude whereas points are positions specified by 3 coordinates with respect to the origin and three base vectors i, j and k that are stored in the first three columns.


1 Answers

You convert vectors between the two coordinate systems by flipping the Y axis. This is equivalent to multiplying by the matrix:

F = [ 1  0  0  0 ]
    [ 0 -1  0  0 ]
    [ 0  0  1  0 ]
    [ 0  0  0  1 ]

To apply your transformation in the flipped coordinate space, you could flip the Y axis, apply your transform, and then flip the Y axis again to get back to the original coordinate space. Written as matrix multiplication, this looks like:

F*(M*(F*x))                [1]

(where M is your matrix). Ok, but that's wasteful -- now we have three matrix multiplies instead of one; fortunately, matrix multiplication is associative, so we re-write:

F*(M*(F*x)) = (FMF)*x

We just need to compute the matrix FMF. Left-multiplication by a diagonal matrix scales the rows of the other matrix by the corresponding elements on the diagonal; right-multiplication scales the columns. So all we need to do is negate the second row and column:

FMF = [ Ux -Vx  Wx  Tx ]
      [-Uy  Vy -Wy -Ty ]
      [ Uz -Vz  Wz  Tz ]
      [  0   0   0   1 ]

From your comment, it sounds like you may not actually want to convert back into the original coordinate system, in which case you could simply use the matrix MF instead of FMF.

[1] More generally, doing a transform, followed by some operation, followed by undoing the transform is called acting by conjugation, and it usually has the form F⁻¹MF. It just happens that our matrix F is its own inverse.

like image 93
Stephen Canon Avatar answered Nov 15 '22 06:11

Stephen Canon