id summary reporter owner description type status milestone component version severity resolution keywords cc 11929 haversine method is inaccurate Charles Karney Barend Gehrels "The following code illustrates a problem with the ""haversine"" strategy for computing great circle distances. It computes the distance between two nearly antipodal points. The relative error in the result is 5e-9, much bigger than you should get with doubles. {{{#!c++ #include #include #include namespace bg = boost::geometry; typedef bg::model::point > pt; int main() { double pi = std::atan2(0, -1); bg::model::segment seg; bg::read_wkt(""SEGMENT(0.000001 0, 180 0)"", seg); double // arc length (converted to degrees dist = bg::distance(seg.first, seg.second) * (180/pi), // the correct distance (in degrees) dist0 = 180 - 0.000001, err = (dist - dist0) / dist0; std::cout << ""relative error "" << err << ""\n""; } }}} Running this code gives {{{ relative error 5.55556e-09 }}} Discussion: * Surely it's a bad idea to embed the algorithm name ""haversine"" into the API. Computing great circle distances is really straightforward. Users shouldn't need to worry about the underlying method. Maybe ""great_circle"" is a better name. * The use of haversines made sense when the log haversine function was tabulated and you needed trigonometric identities involving products to facilitate computations with log tables. Nowadays there are better formulas. * As this example illustrates, it's subject to a loss of accuracy with antipodal points (it takes the arcsine of a number close to 1.) * A good formula to use is given in the Wikipedia article on [https://en.wikipedia.org/wiki/Great-circle_navigation#cite_note-2 great-circle navigation] (this is the formula used by Vincenty in the spherical limit -- but it surely doesn't originate with him). " Bugs new To Be Determined geometry Boost 1.58.0 Problem distance charles.karney@…