-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
getDistanceSimple() returns NaN with specific parameters #129
Comments
Same here. @manuelbieh the docs say its always a number I have more than 1.000 samples that validate that it returns NAN. |
Oh, that's weird. I'll investigate on this. |
@manuelbieh thanks a lot for your time 👍 ! Nice library and project. |
This issue still exists and I have no clue why. I'll buy ice cream for whoever solves this. |
I see it works normally. Tell me what wrong? |
I just ran into this myself and I think I figured it out. It's an issue with floating point arithmetic when attempting to call I have an app that records the user's path travelled over time, and sometimes the location is fixed for a short period leading to
will evaluate to This leads to I think adding a
|
Oh! That is a great catch !
…On Fri, May 31, 2019 at 7:27 PM Jeff ***@***.***> wrote:
This issue still exists and I have no clue why. I'll buy ice cream for
whoever solves this.
I just ran into this myself and I think I figured it out. It's an issue
with floating point arithmetic when attempting to call getDistance() on
two points that are the same or very close to the same point.
I have an app that records the user's path travelled over time, and
sometimes the location is fixed for a short period leading to
getDistance() being called on two copies of the same coordinate pair. The
expected behavior is that getDistance() should return 0, which it does in
most situations. But for certain coordinate pairs, e.g. { latitude:
38.95826, longitude: -77.44167 }, the getDistance() formula
const distance =
Math.acos(
Math.sin(toRad(toLat)) * Math.sin(toRad(fromLat)) +
Math.cos(toRad(toLat)) *
Math.cos(toRad(fromLat)) *
Math.cos(toRad(fromLon) - toRad(toLon))
) * earthRadius;
will evaluate to Math.acos(1.0000000000000002) instead of Math.acos(1)
due to floating point arithmetic and will return NaN as a result.
This leads to getPathLength() also returning NaN if the array of points
contains these coordinate pairs in sequence.
A simple fix would be to add a Math.min(1,x) check to the distance
formula:
const distance =
Math.acos(Math.min(1,
Math.sin(toRad(toLat)) * Math.sin(toRad(fromLat)) +
Math.cos(toRad(toLat)) *
Math.cos(toRad(fromLat)) *
Math.cos(toRad(fromLon) - toRad(toLon))
)) * earthRadius;
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#129?email_source=notifications&email_token=AAJVX4ZWY7V4VYXVJSWXNGLPYFNX7A5CNFSM4DGWROQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWV3X2I#issuecomment-497794025>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJVX44JXK35JHBYK6M7BFDPYFNX7ANCNFSM4DGWROQA>
.
|
Has anyone resolved the "getDistanceFromLine is returning NaN" issue? Are these two issues related? |
I don't encounter this anymore
…On Fri, 6 Mar 2020, 14:15 MajcenT, ***@***.***> wrote:
Has anyone resolved the "getDistanceFromLine is returning NaN" issue? Are
these two issues related?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#129?email_source=notifications&email_token=AAJVX44J7SJI7JZGDP2XSYTRGDZOHA5CNFSM4DGWROQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOBJZ4I#issuecomment-595762417>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJVX46LLKB2NPZK3H4RB2DRGDZOHANCNFSM4DGWROQA>
.
|
This should have been solved by adding a normalizeCosArg helper. Re-open if the error still occurs. |
I still encounter NaN values for these coordinates on [email protected]. Note that the supplied point is almost identical as the supplied lineStart. Edit: Ah, I see you fixed this in 3.3.2. Geolib@latest on npm is still 3.3.1 though.
|
Not sure if it's the near equal longitudes, but this call returns NaN:
The text was updated successfully, but these errors were encountered: