Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flip only one axis of transformation matrix?

I have a 4x4 transformation matrix. However, after trying out the transformation I noticed that movement and rotation of the Y axis is going the opposite way. The rest is correct.

I got this matrix from some other API so probably it is the difference of coordinate system. So, how can I flip an axis of transformation matrix?

If only translation I can add minus sign on the Y translation, but I have no idea about opposite rotation of only one axis since all the rotation is being represented in the same 3x3 area. I thought there might be some way that even affect both translation and rotation at the same time. (truly flipping the axis)

like image 822
5argon Avatar asked Jun 29 '16 10:06

5argon


People also ask

How do you invert a transformation matrix?

The inverse of transformation matrix [R|t] is [R^T | - R^T t].

How do you flip a matrix about the y-axis?

The Math. A flip transformation is a matrix that negates one coordinate and preserves the others, so it's a non-uniform scale operation. To flip a 2D point over the x-axis, scale by [1, -1] , and to flip over the y-axis, scale by [-1, 1] .

How do you rotate a matrix counterclockwise?

To rotate counterclockwise about the origin, multiply the vertex matrix by the given matrix. Example: Find the coordinates of the vertices of the image ΔXYZ with X(1,2),Y(3,5) and Z(−3,4) after it is rotated 180° counterclockwise about the origin.


2 Answers

Edit: I'm pretty sure the operation you're looking for is changing coordinate systems while maintaining Z-up or Y-up. In this case, try setting all the elements of the second column (or row) of your matrix to their inverse.


This question would be better for the Math StackExchange. First, a really helpful read on rotation matrices.

The first problem is the matter of rotation order. I will be assuming the XYZ rotation order. We know the rotation matrices for each axis is as follows:

Rotation matrices for each XYZ axis component

Given a matrix derived from the same rotation order, the resulting matrix would be as follows, where alpha is the X angle, beta is the Y angle, and gamma is the Z angle:

Completed rotation matrix for XYZ rotation order

You can derive the individual components of each axis angle from this matrix. For example, you can derive the Y angle from -sin(beta) using some inverse trig. Given beta, you can derive alpha from cos(beta)sin(alpha). You can also derive gamma from cos(beta)sin(gamma). Note that the same number in the matrix can represent multiple values (e.g. sin(0)=0 and sin(180)=0).

Now that you know alpha, beta, and gamma, you can reverse beta and remake the rotation matrix.

There's a good chance that there's a better way to do this using quaternions, but you should ask the Math StackExchange these kinds of language-agnostic questions.

like image 73
meepzh Avatar answered Sep 28 '22 09:09

meepzh


Much shorter answer: if you are not careful with your frame orientation many things down your pipeline are likely to have a bad hair day. The reason is "parity", a.k.a. "frame orientation", a.k.a. "right-handedness" (or rarely left-handedness). Most 3D geometry tools and libraries that work together normally assume implicitly that all coordinate systems in play are right-handed (or at least consistently-handed). Inverting the orientation of just one axis in a coordinate system changes its orientation from right to left handed or viceversa.

So, suggestion for things to check & try in your problem:

  • Check that the frame you get from your API is right-handed. You do so by computing the determinant of the 3x3 rotation part of your 4x4 transform matrix: it must be +1 or very close to it.

  • If it is -1, then flip one if its axis, i.e. change the sign of one of the columns of the 3x3 rotation.

  • Note carefully: I said "columns" because I assume that you apply a transform Q to a point x by multiplying as Q * x, x being a 4x1 column vector with the last component equal to one. If you use row vectors left-multiplied by Q you need flip a row.

  • If that determinant is +1, you have a bug someplace else.

like image 37
Francesco Callari Avatar answered Sep 28 '22 08:09

Francesco Callari