Let's say I want to figure out the orientation of my cell phone. Assume that the phone has two internal sensors that report orientation (a quaternion), but both are a bit unreliable, so I'd like to use them together.
HOWEVER, the coordinate frames the sensors report a quaternion are not the same.
1) Sensor 1 reports q1, a quat in the following frame: +x = up, +y = right, +z = forward
2) Sensor 2 reports q2, a quat in the following frame: +x = down, +y = forward, +z = left
Note that both frames are right handed, and there exists a quaternion that rotates frame 1 to frame 2 (I think).
I'd like to apply a rotation to whatever orientation I'm getting from sensor 1, so the data roughly matches readings from sensor 2.
qx * q1 ~= q2
I'd like to figure out what qx is.
ALTERNATE SOLUTION:
I was able to convert q1 into q2 frame using:
q1_in_q2_frame = [-q1i, q1k, q1j, q1]
But, I'd like to achieve this result by figuring out what qx is, because the coordinate frames are not necessarily like what I said before, they could be more arbitrary. Imagine sensor 2 always resets its frame to whatever orientation the cell phone was in when you turn it on/off, so a new qx has to be calculated.
WHAT I'VE TRIED:
I thought I could just multiply the following equation by q1' from left:
qx * q1 ~= q2
qx * q1 * q1' = q2 * q1'
qx = q2 * q1'
While the above solution gives me a correct mapping for the current values of q1 and q2, qx becomes no longer valid when I rotate the cell phone.
UPDATE:
I think I made an error in my quaternion multiplications.
Instead of qx * q1 ~= q2, I should really have: qx * q1 * qx' ~= q2
But given q1 and q2, how do I figure out qx now?
There is a simple algebraic solution in terms of quaternions (to your revised question.)
If $v_1$ and $v_2$ are unit quaternions with real part zero, then $q=\frac{v_1(v_1+v_2)}{|v_1+v_2|}$ is a quaternion such that $\bar{q}v_1q=v_2$. The caveat is, of course, that $v_1$ and $v_2$ do not point in opposite directions, so that the division is defined. If they point in opposite directions, well, you can take any 180 degree rotation in a plane containing the vectors to achieve your goal.
Why does this work? If you go digging, you'll find the formula for $q$ to rotate an element of $\mathbb R^3$ to another (both represented as pure imaginary quaternions with zero real part) then the way to do it is to compute $\cos(\theta/2)-\sin(\theta/2)v_3$ where $v_3$ is the (right hand) unit normal to the plane spanned by $v_1$ and $v_2$, and $\theta$ is the angle measured between $v_1$ and $v_2$.
Now it turns out that $v_1v_2=-\cos(\theta)+\sin(\theta)(v_1\times v_2)$ and since its negative also represents the same rotation, we can see we're not far off: our angle is just double what it needs to be. What to do then?
That's where $\frac{v_1+v_2}{|v_1+v_2|}$ comes in: it's a new vector which produces the same unit normal as before, but now the angle has been halved.
Now, you say, "but I don't want $q_1$ and $q_2$ to have zero real part, I want them to be arbitrary." But that's OK, because when you conjugate with a unit quaternion, it leaves the real part alone. So all you need to do is to compute $q$ as I described for the pure quaternions parts of $q_1$ and $q_2$, and that will work to satisfy $\bar{q}q_1q=q_2$.