MATLAB – How to Compute Angle Between Quaternions

MATLABquaternions

I am working on a project where I have many quaternion attitude vectors, and I want to find the 'precision' of these quaternions with respect to each-other.

Without being an expert in this type of thing, my first thought is to find the angle between each (normalized) quaternion, and then find the RMS of that angle. That will give a measure of the precision of our attitude measurements. I was going to use a simple dot product to get this angle.

I don't know that this is a good solution though. Don't know if the dot product will necessarily work between quaternions though.

Note that just want a scalar representation of the pointing precision, and that the differences will on the order of arcseconds. I had also thought to convert to Euler Angles and then just use the vector part of that the Euler Angles.

Doing the math in MATLAB, but really I'm just looking for the theory behind it.

Thanks for the help!

Best Answer

For small differences the Euclidian distance between the two vectors is sufficient. To get an exact answer you would have to use the following process. Assume your quaternions $x$ and $y$ are represented as $x = [x_0, x_1, x_2, x_3]$ and $y = [y_0, y_1, y_2, y_3]$ and that they are unit quaternions. Then let $\operatorname{inv}()$ denote the inverse of a quaternion which for unit quaternions is equivalent to the conjugate (i.e. $ \operatorname{inv}(x)=\operatorname{conj}(x) = [x_0, -x_1, -x_2, -x_3]$). Then the quantity that captures the true difference is $z = x*\operatorname{conj}(y)$. We can then recover the angle using $\theta = 2\arccos(z_0)$. Then $\theta$ gives you an angle by which the two quaternions differ.

Related Question