# Angle between two vectors with noisy data?

Given two vectors V1=(x1,y1,z1) and V2=(x2,y2,z2) I can calculate the angle between the two vectors using the dot product of the two vectors and their magnitudes.

This approach, however, is only acceptable if my data on the two vectors is of infinite precision and contains no error. If one of my vectors is a cardinal unit vector, such as (0,0,1), then two axes of data are thrown away by the dot product operation and only one used to calculate the angle. This is disastrous if I am operating with noisy data (such as might be collected from an accelerometer), or if the angle is close to that axis where that component of the vector carries the least data.

I have seen an algorithm which involved calculating the angles from all three axes to each of the vectors, weighting those calculations based on the magnitudes of some of the components, and then combining the results into the best approximation of the angle between the vectors. Can anyone provide that algorithm?

-

If you treat the two known vectors, I call $a$ and $b$, as sides of a triangle, then the third side is $b-a$. Once you have found vectors for the three sides of the triangle, you can find their magnitude to get the lengths of the edges and then use the cosine rule to work out the desired angle.