Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question

I'm not sure if this will work or not.

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.

share|cite|improve this answer
That's a very good idea! I shall try it. – Sparr Oct 23 '12 at 4:17
Upon trying it... it is better than the naive approach, but still fails to take the relative reliability of the measurements into account. Assume the noise/error on all three axes is similar. When the angle is close to 0 or 180 degrees, the same amount of noise on X and Y will produce less angular error than on Z, so X and Y should be "trusted" more in the angle calculation. – Sparr Oct 23 '12 at 5:02
@Sparr: Can you explain how it is better than the "naive approach"? Unless I'm misunderstanding something, it should give exactly the same results as the usual dot product formula. – Rahul Oct 23 '12 at 6:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.