0

So I am using the Matterport 3D dataset for my task and it has described the oriented bounding box using the standard structure with one change as follows:

"obb": {
        "centroid":[3.39208,-1.72134,1.13262],
        "axesLengths":[1.11588,0.619098,0.439177],
        "dominantNormal":[-0.707107,-0.707107,0],
        "normalizedAxes":[0,0,1,-0.707107,0.707107,0,-0.707107,-0.707107,0]
      }

I understand that the oriented bounding box is typically defined by the centroid, local coordinate system axes, and lengths along those axes.

In my case, considering that the object is only rotated around the vertical axis (z-axis) in world coordinate frame, I want to find out the angle by which it is rotated around the z-axis. But for that, I need the rotation matrix which transforms the world coordinate system into the local coordinate system. In standard representation case, the rotation matrix is the just 3x3 matrix with the axes as column vectors. However, in this case, if you look at the normalized axes array there are 9 values given with no convention as to which axis should be the first column vector or second column vector in rotation matrix.

With the assumption that, the object position is vertical and rotated only around the z-axis, I can determine the last column of the rotation matrix. For example, [0, 0, 1] in the aforementioned example. But how to determine the other two axes? Is there a way to take "dominantNormal" information into consideration in determining that?

bhushan
  • 470
  • 3
  • 14
  • Isn't the rotation matrix encoded in `normalizedAxes`? They appear to be three mutually orthogonal unit vectors. – John Alexiou Nov 09 '18 at 17:29
  • Yes, so rotation matrix essentially has the axes of the new coordinate system as the column vectors. But in this case, as I have mentioned, considering that the object is only rotated around the z-axis, the last column of the rotation matrix will always be [0, 0, 1] but how do I determine what would be the first/second column? is the normalisedAxes first three values are the first column or second column? – bhushan Nov 09 '18 at 18:12
  • Edit the question to reflect that you now want the three Euler angles from a rotation matrix. Better yet, [look online](https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm) – John Alexiou Nov 09 '18 at 21:03

2 Answers2

1

Assuming that the normalizeAxes property has the following meaning:

[X1, X2, X3, Y1, Y2, Y3, Z1, Z2, Z3]

Then the local-to-world rotation matrix's columns are equal to the vectors XYZ:

    | X1 Y1 Z1 |
R = | X2 Y2 Z2 |
    | X3 Y3 Z3 |

The world-to-local rotation matrix is of course just the inverse (= transpose) of this:

         | X1 X2 X3 |
inv(R) = | Y1 Y2 Y3 |
         | Z1 Z2 Z3 |

Taking the translation centroid = [C1, C2, C3] into consideration:

    | X1 Y1 Z1 C1 |
T = | X2 Y2 Z2 C2 |
    | X3 Y3 Z3 C3 |
    | 0  0  0  1  |

         | X1 X2 X3 -dot(C, X) |
inv(T) = | Y1 Y2 Y3 -dot(C, Y) |
         | Z1 Z2 Z3 -dot(C, Z) |
         | 0  0  0       1     |

Not sure what dominantNormal represents (there doesn't seem to be any openly available documentation for it); might be metadata for shading, or a measure of the geometry distribution within this OBB.

meowgoesthedog
  • 14,670
  • 4
  • 27
  • 40
  • I understand that rotation matrix is encoded in the vectors but we do not know if the normalizedAxes are [X1, X2, X3, Y1, Y2, Y3, Z1, Z2, Z3] or [X1, X2, X3, Z1, Z2, Z3, Y1, Y2, Y3 ]. As I mentioned in the question, considering the object is rotated only around the Z axis [0, 0 ,1] the z-axis column vector in the rotation matrix will be [0, 0, 1] which I can get get from the _normalizedAxes_ but how do I determine what is the x-axis, y-axis columns. – bhushan Nov 09 '18 at 18:07
  • @bhushan you'll have to find out from the documentation, which seems to be proprietary (wasn't able to find it directly from their website); I assume that since you are working with this product you would also have access to it. Luckily the basic math principles will remain unchanged. – meowgoesthedog Nov 09 '18 at 18:10
  • Yes that is the issue, documentation does not mention it so I was wondering if it can be derived from the available data. Anyway, thank you for your input. – bhushan Nov 09 '18 at 18:14
  • @bhushan yes that should be doable; experiment with swapping the vectors XYZ or their components around, and see what effect this has. e.g. it's clear from your constraint that the Z axis is in-fact the **first** 3 numbers. – meowgoesthedog Nov 09 '18 at 18:16
0

Let us take the example given in the problem. Normalized axes are given but not in any particular order as follows.

"normalizedAxes":[0,0,1,-0.707107,0.707107,0,-0.707107,-0.707107,0]

Since we know that, the object is rotated only around the z-axis, the third column in the rotation matrix would be [0, 0, 1]. So that leaves us with two columns; let us call them axis_0, axis_1.

So,

axis_0 = [-0.707107, 0.707107, 0] 
axis_1 = [-0.707107, -0.707107, 0]

You can calculate the angle that each of this axis makes with the x-axis in the global coordinate system using the inverse tangent function. Let us say, the angle made by the axis_0 and axis_1 are angle_0 and angle_1 respectively.

Either of the following relation has to be true as we know that axis_0 and axis_1 are orthogonal.

angle_0 = angle_1 + 90 or angle_1 = angle_0 + 90

So with the aforementioned example, you can notice that,

angle_0 = 135 degrees
angle_1 = 225 degrees (-135 degrees)

As we consider the counterclockwise rotation as positive, the axis which makes the smaller angle would be the first column in the rotation matrix and the other axis would be the second column in the rotation matrix.

The rotation matrix, in this case, looks like the following:

[ [ -0.707107, -0.707107,  0],
  [ 0.707107,  -0.707107,  0],
  [ 0,          0,         1],
]

If you use arctan2 function, be careful handling the special cases in which the axes are rotated clockwise and rotated y-axis and x-axis lie in the first and fourth quadrant respectively.

bhushan
  • 470
  • 3
  • 14