If you don’t mind ignoring the slight flattening of the Earth (and your hosted Haversine code does this anyway), consider converting all your spherical (lat / long) coordinates to a 3D unit of length of Cartesian coordinates, per:
http://en.wikipedia.org/wiki/Spherical_coordinate_system
Then your spherical distance between the Cartesian coordinates p1 and p2 simple:
r * acos(p1 . p2)
Since p1 and p2 will have a unit of length, this will be reduced to four multiplications, two additions and one inverse operation of three pairs.
Also note that point product computation is an ideal candidate for optimization, for example. via GPU, MMX extensions, vector libraries, etc.
In addition, if your intention is to arrange pairs by distance, potentially ignoring more distant pairs, you can defer the expensive part of the r*acos() equation by sorting the list only by the value of the point of sale, since for all valid inputs (i.e. E. range [-1, 1] ), he guaranteed that:
acos(x) < acos(y) if x > y
Then you just take acos() values that you are really interested in.
Re: potential inaccuracies using acos() , this is really significant if you use variables with the same float precision. Using a double with 16 significant digits should give you the distance with an accuracy of one meter or less.
Alnitak
source share