How to calculate the angle between two vectors, defined by 3 points on the earth?

2.4k Views Asked by At

I want to develop a formula to calculate the angle between two vectors. The vectors will be OX and OY (from point O to X , and Y), where the points are defined by their latitude and longitude values.

I know that there is a little problem when calculating the angle between 3D vectors, so it could be calculating the angles between OX' and OY' prime, where the points X' and Y' are the projections of X and Y, on the plane that "skews" earth on point O.

Any ideas how to formulize this ?

Thanks in advance :)

2

There are 2 best solutions below

0
On BEST ANSWER

If you project your vectors onto a plane, you can derive the angle from the dot product. $$a \cdot b = ||a||\,||b|| \cos \theta$$

Or you may want the spherical angle, in which case you will also need the radius of your sphere.

1
On

Calculate the $x,y,z$ and $X,Y,Z$ coordinates of the two points. For this you need the formulas for spherical coordinates: $(x,y,z) = (\cos a \cos b, \cos a \sin b, \sin a)$. Then calculate the scalar product of the two vectors: $p = x X + y Y + z Z$. Then get the angle as $\arccos(p)$.

Edit: I am sorry, I thought O would be the centre of the earth. With 3 points on the earth, the other answer is correct (project onto the plane that is tangent to earth at point O).