Quaternion from global space to local space

1.1k Views Asked by At

I've searched but have not found a response for this question specifically.

I have a smartphone with a sensor that gives me a quaternion representing its absolute rotation relatively to the following axis:

X - tangent to Earth, pointing to East; Y - tangent to Earth, pointing to the North; Z = X cross Y, orthogonal to Earth, pointing upwards.

When the smartphone screen is parallel to the ground plane and aligned to the East, the sensor reads Q = 1 + 0i + 0j + 0k.

I know that, for any 2 quaternions Q and R, the offset rotation from Q to R, i.e., D such that R = D * Q, would be R * Q^-1.

Now, I'd like to take a reference frame (calibration) and, for any quaternion Q, obtain a new quaternion Q' that represents offset rotation from the calibration to the current rotation, but using the device itself as reference, i.e.:

X' - tangent to the device screen, pointing right of the device; Y' - tangent to the device screen, pointing up of the device; Z' = X' cross Y', orthogonal to the screen, pointing out from it.

How can I do that? Please, be gentle with me, I'm not a mathematician, just a poor programmer. :-)

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

To translate your 'earth' coordinates into 'phone' coordinates, you would just have to rotate the $X,Y$ plane counterclockwise by $\theta$ radians where $\theta$ is the angle (counterclockwise) from $X$ to $X'$.

So, you'd need a quaternion that looks like $q=\cos(\frac{\theta}{2})+\sin(\frac{\theta}{2})k$.