Repository navigation
Conversation
…ength lambda12 gets the derivative of lam12 from meridian_length, which computes the reduced length only when EnableReducedLength is set. A distance-only instantiation, like the one strategy::karney uses for length, therefore got a zero derivative and fell back to bisection on every iteration. Starting from the bracket [0, 180], the first bisection step is the azimuth 90, and when beta2 is -beta1 up to rounding, lambda12 takes the square root of a slightly negative number for cos_alpha2. The distance comes out NaN, and normalize_unit_vector asserts. For example, from (0, -45) to (1e-10, 45) on WGS84 the distance was NaN instead of 9969888.755955 m. A scan of 9.6 million segments between latitudes near -45 and 45 found 186902 NaN results before, none after. Always request the reduced length for the derivative, like GeographicLib does. Results now agree with an independent solver to the micrometer (the bisection was off by up to 1.3 mm near the equator), and length is about 4 times faster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lambda12(boost/geometry/formulas/karney_inverse.hpp) takes the derivative oflam12frommeridian_length, butmeridian_lengthcomputes the reduced length only whenEnableReducedLengthis set.strategy::karneyuses a distance-only instantiation forlength, so the derivative was always zero. Newton's method never ran, and every iteration fell back to bisection.The first bisection step from the bracket [0, 180] is azimuth 90. When
beta2equals-beta1up to rounding,lambda12then takes the square root of a slightly negative number forcos_alpha2. The distance comes out NaN, andnormalize_unit_vectorassertsh > 0. Example on WGS84: from (0, -45) to (1e-10, 45), the distance should be 9969888.755955 m but was NaN, in both directions. This showed up in ClickHouse'slengthSpheroid: ClickHouse/ClickHouse#127764The fix always requests the reduced length for the derivative, as GeographicLib does.
lengthis about 4 times faster on those segments.