-
Notifications
You must be signed in to change notification settings - Fork 229
Improve short-distance accuracy of Andoyer inverse #1461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mjacobse
wants to merge
6
commits into
boostorg:develop
Choose a base branch
from
mjacobse:improve_andoyer_inverse_accuracy
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+30
−20
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
07c112c
Improve short-distance accuracy of Andoyer inverse
mjacobse 7c18419
Qualify sqrt call with math namespace
mjacobse d3a4f79
Add curly braces for if statement
mjacobse 38ec1bd
Improve readability of formulas
mjacobse 14b6c8e
Update test reference value
mjacobse 905ea42
Add comment for haversine - cosine relation
mjacobse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,28 +73,35 @@ class andoyer_inverse | |
|
|
||
| CT const c0 = CT(0); | ||
| CT const c1 = CT(1); | ||
| CT const c2 = CT(2); | ||
| CT const pi = math::pi<CT>(); | ||
| CT const f = formula::flattening<CT>(spheroid); | ||
|
|
||
| CT const dlon = lon2 - lon1; | ||
| CT const dlat = lat2 - lat1; | ||
| CT const sin_dlon = sin(dlon); | ||
| CT const cos_dlon = cos(dlon); | ||
| CT const hav_dlon = math::hav(dlon); | ||
| CT const sin_lat1 = sin(lat1); | ||
| CT const cos_lat1 = cos(lat1); | ||
| CT const sin_lat2 = sin(lat2); | ||
| CT const cos_lat2 = cos(lat2); | ||
| CT const hav_dlat = math::hav(dlat); | ||
|
|
||
| // H,G,T = infinity if cos_d = 1 or cos_d = -1 | ||
| // using the haversine formula instead of the cosine law for better accuracy around short distances | ||
| // H,G,T = infinity if hav_d = 0 or hav_d = 1 | ||
| // lat1 == +-90 && lat2 == +-90 | ||
| // lat1 == lat2 && lon1 == lon2 | ||
| CT cos_d = sin_lat1*sin_lat2 + cos_lat1*cos_lat2*cos_dlon; | ||
| // on some platforms cos_d may be outside valid range | ||
| if (cos_d < -c1) | ||
| cos_d = -c1; | ||
| else if (cos_d > c1) | ||
| cos_d = c1; | ||
|
|
||
| CT const d = acos(cos_d); // [0, pi] | ||
| CT hav_d = hav_dlat + cos_lat1*cos_lat2*hav_dlon; | ||
| // on some platforms hav_d may be outside valid range | ||
| if (hav_d < c0) | ||
| hav_d = c0; | ||
| else if (hav_d > c1) | ||
| hav_d = c1; | ||
|
|
||
| CT const sin_d_half = sqrt(hav_d); | ||
| CT const d_half = asin(sin_d_half); | ||
|
mjacobse marked this conversation as resolved.
|
||
| CT const d = c2 * d_half; // [0, pi] | ||
| CT const sin_d = sin(d); // [-1, 1] | ||
|
|
||
| if BOOST_GEOMETRY_CONSTEXPR (EnableDistance) | ||
|
|
@@ -103,8 +110,8 @@ class andoyer_inverse | |
| CT const L = math::sqr(sin_lat1+sin_lat2); | ||
| CT const three_sin_d = CT(3) * sin_d; | ||
|
|
||
| CT const one_minus_cos_d = c1 - cos_d; | ||
| CT const one_plus_cos_d = c1 + cos_d; | ||
| CT const one_minus_cos_d = c2 * hav_d; | ||
| CT const one_plus_cos_d = c2 - one_minus_cos_d; | ||
| // cos_d = 1 means that the points are very close | ||
| // cos_d = -1 means that the points are antipodal | ||
|
mjacobse marked this conversation as resolved.
|
||
|
|
||
|
|
@@ -141,7 +148,7 @@ class andoyer_inverse | |
| // correctly and consistently across all formulas. | ||
|
|
||
| // points very close | ||
| if (cos_d >= c0) | ||
| if (hav_d <= CT(0.5)) | ||
| { | ||
| result.azimuth = c0; | ||
| result.reverse_azimuth = c0; | ||
|
|
@@ -164,7 +171,8 @@ class andoyer_inverse | |
| } | ||
| else | ||
| { | ||
| CT const c2 = CT(2); | ||
| CT const M = cos_lat1 * sin_lat2; | ||
| CT const N = sin_lat1 * cos_lat2; | ||
|
|
||
| CT A = c0; | ||
| CT U = c0; | ||
|
|
@@ -177,9 +185,7 @@ class andoyer_inverse | |
| } | ||
| else | ||
| { | ||
| CT const tan_lat2 = sin_lat2/cos_lat2; | ||
| CT const M = cos_lat1*tan_lat2-sin_lat1*cos_dlon; | ||
| A = atan2(sin_dlon, M); | ||
| A = atan2(sin_dlon*cos_lat2, M - N*cos_dlon); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here the |
||
| CT const sin_2A = sin(c2*A); | ||
| U = (f/ c2)*math::sqr(cos_lat1)*sin_2A; | ||
| } | ||
|
|
@@ -195,9 +201,7 @@ class andoyer_inverse | |
| } | ||
| else | ||
| { | ||
| CT const tan_lat1 = sin_lat1/cos_lat1; | ||
| CT const N = cos_lat2*tan_lat1-sin_lat2*cos_dlon; | ||
| B = atan2(sin_dlon, N); | ||
| B = atan2(sin_dlon*cos_lat1, N - M*cos_dlon); | ||
| CT const sin_2B = sin(c2*B); | ||
| V = (f/ c2)*math::sqr(cos_lat2)*sin_2B; | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.