- Local time
- Today, 03:07
- Joined
- Feb 28, 2001
- Messages
- 30,903
Starting from the WIKIPEDIA article on great circle calculations, I was able to implement their EXACT formula (not Haversine based) in about 30 minutes. You know what took the most time? If you have degrees, minutes, and seconds of arc, you need to convert that to radians first. THAT is the hard part. After that, it is all sines, cosines, and exactly one ATN (Arc Tangent) function. Couple of terms get squared. One Square Root involved. A simple division, some multiplication, and that's it. The WIKIPEDIA article even gives you the radius of the earth to use in determining the length of the chord. And they give you a sample calculation so you can test your algorithm.
Their advice if you want to do it their way is, all math must be DOUBLE format because of the differences involved. But (they say) their formula is not an approximation, it is exact. If you are doing their way, it helps to know PI to DOUBLE precision. Such as
PI = 3.141592565689793 (roughly speaking).
Now, having looked at the formula with a (slightly) more educated eye, because I worked in that industry for a while, I can say confidently that as long as you avoid two extreme cases, the math doesn't even involve unusually small or unusually large numbers, so "catastrophic cancellation" errors won't be likely. After all, SIN and COS functions range from zero to one. No gargantuan values there.
The cases to avoid using their exact formula because of extremes in the math:
1. One of the points is smack-dab on the north or south pole. That makes some of the cosines unusually small, leading to possible issues in the denominator of the one big division that they have. But usually folks don't get within 10 degrees of either one of the poles, so no great issues there.
2. The two reference points are antipodal i.e. exactly half-way around the world from each other. Said another way, the two points and the center of the earth form a straight line rather than defining a plane.
In all other cases, the result is pretty straight-forward.
Their advice if you want to do it their way is, all math must be DOUBLE format because of the differences involved. But (they say) their formula is not an approximation, it is exact. If you are doing their way, it helps to know PI to DOUBLE precision. Such as
PI = 3.141592565689793 (roughly speaking).
Now, having looked at the formula with a (slightly) more educated eye, because I worked in that industry for a while, I can say confidently that as long as you avoid two extreme cases, the math doesn't even involve unusually small or unusually large numbers, so "catastrophic cancellation" errors won't be likely. After all, SIN and COS functions range from zero to one. No gargantuan values there.
The cases to avoid using their exact formula because of extremes in the math:
1. One of the points is smack-dab on the north or south pole. That makes some of the cosines unusually small, leading to possible issues in the denominator of the one big division that they have. But usually folks don't get within 10 degrees of either one of the poles, so no great issues there.
2. The two reference points are antipodal i.e. exactly half-way around the world from each other. Said another way, the two points and the center of the earth form a straight line rather than defining a plane.
In all other cases, the result is pretty straight-forward.