As the title says, I have two rotation matrices, $ R_1 $ and $ R_2 $. Both are rotation matrices that transform from the origin coordinate system $O$ to positions $1$ and $2$ (ignoring any translation).
What I want to calculate is the angular difference on the XZ plane between the Z1 and Z2 axis.
The way I see it is I can either align the $front$ vectors of $ R_1 $ and $ R_2 $ or I have to project the $up$ vector (Z unit vector) of $R1$ to the XZ plane formed by the $up(Z-axis)-right(X-axis)$ unit vectors of $R2$.
Is my thinking correct ? The reason I am asking is because I tried both and I am not getting the expected results.
Option 1 - Align front vectors
- I got the front vector (3rd row) from $ R_1 $ and $ R_2 $ and calculated the cross product and dot product, got the skew symmetric matrix and then calculated the rotation $R$ using the Rodrigues formula.
- Rotated my original $R_1$ to $R_{1}^{'} = R * R_1 $ and finally
- Got the angle from dot product for the up vectors (2nd row) of the $R_{1}^{'}$ and $R_2$
Option 2 - Project to XZ plane
- Get the up and right, vector from $R_2$ that is 1st and 2nd row and calculate the cross product to get the normals of the plane. (Dont really need to calculate as it will be the 3rd row of the rotation matrix)
- Project up vector of $R_1$ to XZ plane
- Get the angle from the dot product of the projected vector and the up vector of the $R_2$
Problem is I am seeing some rotations that I was not expecting so clearly something is wrong. By that I mean that rotation around X or Y axis should give me a $0$ rotation angle around the Z.
Any ideas ?
I can provide examples if needed, just did not want to clutter the post.