Reputation: 1
I'm currently trying to compute the rotation angles of an oriented bounding box around each axis using Open3D. My initial approach was to use ICP (Iterative Closest Point) to find the transformation matrix for rotating a provided bounding box so it aligns with a reference bounding box. However, I believe this method might be overkill for my goal.
My main problem is that the default transformation matrix given by Open3D's bounding box always leads to inconsistent results. I'm hypothesizing that it's feasible to achieve the desired outcome using standard geometric calculations, by leveraging the normal of the plane.
I've also written some pytests to validate new methods. I'm looking for any alternative methods or guidance on how I can make this more straightforward and consistent.
Github: https://github.com/simondegheselle/stackoverflow_q_calculating_rotation_obb
Upvotes: 0
Views: 700
Reputation: 7198
To align an "axis-system-1" to other "axis-system-2" the first thing is move system-1 so its origin is the same as for system-2.
We will use some matrices from here, but be aware that to rotate an object first put it in "axis-system-2". That's why I tell about "move the system-1".
The matrices that represent a rotation are in the Wikipedia.
The first step is making a rotation such that axis X-1 overlaps axis X-2.
This can be done by using a rotation axis that is perpendicular to both X-1 and X-2. Calculate the vector for this axis by the cross-product of X-1 and X-2.
Let's say the X-axis in system-1 (represented by vector 1, 0, 0) is represented in system-2 by unitary ("normalized" length=1) vector (a, b, c). Vector for X-2 in system-2 coords is (1, 0 , 0) The cross-product {X-1}x{X-2} gives the vector P(0, c, -b)
. Scale it so its length becomes 1.
The angle needed is (dot product os X-1·X-2) cos(t) = (a, b, c)·(1, 0, 0) = a
You also need sin(t) = 1 - sqrt(a)
Use the "Rotation matrix from axis and angle" given in the Wikipedia with axis u=P and angle=t.
Now we have X-1 and X-2 to be the same axis, you just need a rotation around X-2 axis so axis Y-1 and Y-2 match (Z-axis will automagically match too).
The angle for this rotation can be calculated by dot product of Y-2 in system-2 after X-rotation applied (multiply by the calculated matrix above and normalize it) and Y2 (0 , 1, 0) vector.
You can see we have calculated and used two matrices. If you want any point expressed in system-1 to be rotated for system-2 then just multiply both matrices (order matters a lot) and get the full-transformation-matrix, which you can apply to any point
Upvotes: 0