Can you extract the horizontal component of the change of two quaternions?

245 Views Asked by At

I receive orientation data as quaternions, and I'm interested in finding the ground-planed component of the change in angle.

I know that the arccosine of the dot product of two quaternions gives me the angle. For instance, the difference between an object oriented at $(0, 0, 0)$ and $(0, 90, 0)$ (roll, yaw, pitch) does give me $90$ degrees. I am not sure what the $120$ degrees from $(0, 90, 0)$ and $(90, 0, 0)$ represents in the real world, though.

I would like to extract the change in angle only around the world vertical axis. So, $(0, 90, 0)$ and $(90, 0, 0)$ would give me $90$, while $(0, 90, 45)$ and $(90, 0, 60)$ would be $30$ degrees.

Is there any way of finding that difference? Converting to Euler angles gives me a singularity near $(0, -90, 0)$, and I end up getting numbers like $(-150, 0.2, -170)$ etc, so I cannot rely on the output being correct.

1

There are 1 best solutions below

0
On BEST ANSWER

@Coolwater was correct. Multiplying the quaternion by the other's inverse, then converting to Euler angles, gives the correct answer. I will be trying out different configurations in the lab tomorrow.

I made a Quaternion class which incorporates the definitions in the link @Coolwater gave.

>>> np.rad2deg((Quaternion(np.deg2rad([0, 90, 0]))
                * ~Quaternion(np.deg2rad([90, 0, 0]))).to_euler())
array([-90.,  90.,   0.])
>>> np.rad2deg((Quaternion(np.deg2rad([0, 90, 0]))
                * ~Quaternion(np.deg2rad([0, 0, 0]))).to_euler())
array([ -0.,  90.,   0.])
>>> np.rad2deg((Quaternion(np.deg2rad([0, 90, 45]))
                * ~Quaternion(np.deg2rad([90, 0, 60]))).to_euler())
array([-90.,  30.,  45.])

Taking yaw (the second item, so _[1]), would give me the angle I am looking for.