A person holds his phone and rotates it in space in a sequence. I am able to obtain a sequence of quaternions from the phone's motion sensors representing the rotation of the phone from the phone coordinate system to the world coordinate system.
A second person holds his phone and again rotates it in a sequence. I want to determine if the second person is rotating in the same sequence as the first person. I learned that I can use Dynamic Time Warping to compute a similarity score, however, my problem is a little more difficult. I do not know if the second person is facing the same direction as the first person when rotating his phone.
The following graph depicts the phone's coordinate system.
The following graph depicts the world coordinate system
As an example with a sequence of $1$, the first person is facing north. He holds the phone flat (screen pointing up), with the top side of the phone pointing away from his body. In this case, the phone's coordinate system coincide with the world's coordinate system. I get an identity quaternion. The second person is facing west, and he holds the phone in the same way. Because the phone's coordinate system is $90$ degrees around $Z$ off from the world coordinate system, I get a quaternion of $(0i, 0j, 0.7k, 0.7)$, which is basically a rotation of $90$ degree around $Z$.
From the person's perspective, both hold the phone in the exact same orientation. The question is that how do I find the angle of rotation around $Z$ such that it minimizes the differences between the two quaternion sequences? In this example, I want the algorithm to say this is an exact match.
Even though the example uses a sequence of $1$, I really want to match a longer sequence of rotations.
I am only interested in rotation similarity, and do not care about translation in space. I also consider a phone facing up to be different from a phone facing down.
I thought about decomposing a quaternion into a rotation around $Z$ and another quaternion without the $Z$ component, but I think the decomposition is not unique. Any other ideas what I can do to check if the two sequences of rotations are similar, subject to a constant rotation around $Z$?