Angular Difference between two rotation matrices on XZ plane

3.2k Views Asked by At

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.

  1. 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$
  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.

2

There are 2 best solutions below

0
On BEST ANSWER

What I was proposing was correct. The error I had was that I was not normalizing one of my vectors and thus I had incorrect results in my dot product as I was considering that I had unit lengths.

So what I did was pretty much what I mentioned before. To recap

  1. Project up vector $u_1$ of $R_1$ to the $XZ$ plane of $R_2$, the normal of $XZ$ is the the front vector $f_2$ so it is fairly easy
  2. Calculate the angle between the projected point $pu_1$ and up vector $u_2$ of $R_3$

That way you can get the difference in Roll, that is portrait vs landscape rotation to make it a bit more clear.

1
On

I think a way to calculate what you are asking is:

  • Calculate front vectors of both rotation matrices: v1 and v2

  • Calculate angle between front vectors (v1 and v2) and XZ plane: angle1 and angle2

  • Calculate difference between these two angles: angle1 and angle2

This is the value you are looking for.