# Relative rotations using quaternions [duplicate]

This question is an exact duplicate of:

I have a sensor at some arbitrary orientation (non-zero roll, yaw, pitch) given by quaternion $q_{0}$. I then pitch the sensor to orientation $q_{1}$. When I compute the relative rotation between the two as

$r = q_{1} q_{0}^{-1}$

Then I notice that the relative rotation has roll, pitch and yaw components. Why is this and how do I get a pure pitch from $r$?

## marked as duplicate by Grigory M, TMM, Dan Rust, Newb, Brian RushtonJan 2 '14 at 1:12

This question was marked as an exact duplicate of an existing question.

• The question has been asked before but didn't have an answer. Even when this is an exact duplicate, it is the old one from same user without answer should be marked as duplicate. not this one with an answer. voted for reopen. – achille hui Jan 2 '14 at 4:04

If you're lucky, and the sensor in its unrotated state is aligned with one of the coordinate axes, like $(1, 0, 0)$, then you can write this as the quarternion $i$; after rotation by $q_1$, you can compute $q_1 i q_1^{-1}$, which is a 4-component quaternion, but its real part will be zero, so it'll have the form $xi + yj + zk$, which you should regard as the vector $v_1 = (x, y, z)$, which will be the direction-vector of the sensor. You can do the same for $q_2$. And then you can take $$\theta = \cos^{-1}( v_1 \cdot v_2 )$$ to be the pitch angle between the two directions.
About what direction do you want to pitch? Around the vector $v_1 \times v_2$ (or its negative...you can try one, and if it doesn't work, try the other).