Closed kenba closed 5 years ago
Indeed it looks like the call to math::polyval
on line 645 of
geometry/util/series_expansion.hpp
is wrong. I think
math::polyval(coeffs2.begin(), coeffs2.begin() + offset, eps);
should be replaced by
math::polyval(coeffs2.begin() + offset,
coeffs2.begin() + offset + m + 1,
eps);
and maybe offset
needs to be initialized to 0
instead of 1
in this
function.
I attempted to implement the changes proposed by @cffk above yesterday (including initialising offset to 0), only to discover that there is also an issue with polyval
and the polynomial coefficients.
math::polyval
evaluates polynomial coefficients in descending eps order, while evaluate_coeffs_C3x
(and the other functions in series_expansion.hpp) define their polynomial coefficients in ascending eps order.
Having the polynomial coefficients in ascending eps order makes them easier to compare with the values in @cffk's paper: Geodesics on an ellipsoid of revolution. However, the GeographicLib Geodesic.cpp
file has the coefficients descending eps order, so it is easier to compare these values in descending eps order.
I compared some of the polynomial coefficients in evaluate_coeffs_C3
with those in @cffk's paper and
Geodesic.cpp
and found that evaluate_coeffs_C3
includes extra coefficients...
This issue could be resolved either by changing math::polyval
and/or reordering/recreating the polynomial coefficients in addition to the above changes.
Note: math::horner_evaluate
evaluates polynomial coefficients in ascending eps order, so if the
polynomial coefficients were changed to descending order, then this function would also need to be changed.
I have just committed a pull request to fix this issue.
It contains the changes proposed by @cffk and calls horner_evaluate
instead of polyval
to evaluate the polynomial coefficients in ascending eps order, i.e. it is the minimum change to fix the issue.
With this change, the example tests pass with both longitude tolerances set to 130 * CALCULATION_TOLERANCE
.
https://github.com/boostorg/geometry/pull/562 is merged. Should I close the issue?
I believe so, but then again I wrote the fix! Charles @cffk is the expert, I would ask his permission if I were you.
I haven't been paying much attention to the boost geometry package lately. So I'm not in a position to provide a decent response here. However, I can recommend a piece of due diligence...
The fact that the original boost implementation goofed on evaluating the series expansion for longitude suggests that the other series expansions used in the solution of the goedesic problem be scrutinized for similar problems too. The other expansions are those for the distance (and the corresponding reverted series), the reduced length + geodesic scale, and the series for the area. (I'm not sure if all of these are used by boost geometry.)
It is not a priority but indeed this (accuracy of geodesic algorithms in Boost Geometry) is something that should be tested more systematically. Thanks for the feedback. I am closing the issue.
The karney_direct formula (
formulas/karney_direct.hpp
) is an implementation of Charles Karney’s GeographicLib Geodesic::Direct function. Accuracy is a key feature of the GeographicLib functions, see #449.I therefore expect the
karney_direct
formula to produce results: azimuth, latitude and longitude, that are very close to those produced by the corresponding GeographicLibGeodesic::Direct
function.Comparing the output of the
karney_direct
formula withGeodesic::Direct
over a grid of latitudes and longitudes, the reverse_azimuths and latitudes match the expected values quite closely but the longitudes are less accurate by over 4 orders of magnitude!, see program below.I believe that the longitude inaccuracy may be caused by a bug in the
evaluate_coeffs_C3
function in theutil/series_expansion.hpp
file: the variablem
is not being passed to themath::polyval
function.The comment above "evaluate_coeffs_C3x" states: "The C++ code ... is generated by the following Maxima script..." Therefore, this issue may be caused by Maxima or the script.