Skip to content
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

Implement Great-circle distance #7

Open
peter279k opened this issue Dec 31, 2018 · 5 comments
Open

Implement Great-circle distance #7

peter279k opened this issue Dec 31, 2018 · 5 comments

Comments

@peter279k
Copy link
Contributor

Please refer this: https://en.wikipedia.org/wiki/Great-circle_distance

@DivineOmega
Copy link
Owner

I believe this is implemented already under the name Haversine distance.

https://github.com/DivineOmega/php-distance/blob/master/src/Types/Haversine.php

Please feel free to double check this though.

@peter279k
Copy link
Contributor Author

peter279k commented Jan 1, 2019

@DivineOmega, thank you for your reply. After checking these two distance formulas, they're different and the Haversine class doesn't implement Great-circle distance formula well.

According to this wiki reference, it has two different formulas in the different condition.

The first formula is as follows:

image

And the distance is: (r is the $greatCircleRadius value)

image

On computer systems with low floating-point precision, the spherical law of cosines formula can have large rounding errors if the distance is small.

The haversine formula is numerically better-conditioned for small distances:

image

And the second formula is same as Haversine distance.

I think we don't have to implement the first formula I mention because this formula will have the rounding errors on the computing system, right?

@DivineOmega
Copy link
Owner

Interesting. This is not something I have considered before.

The wiki also states that:

For modern 64-bit floating-point numbers, the spherical law of cosines formula [...] does not have serious rounding errors for distances larger than a few meters on the surface of the Earth.

@peter279k
Copy link
Contributor Author

peter279k commented Jan 2, 2019

@DivineOmega, thank you for your reply.

I think we can get the two points are as follows:

  • if the two points are a kilometer apart on the surface of the Earth, the cosine of the central angle comes out 0.99999999 (means the cos value is very closed to 1.), The haversine formula is numerically better-conditioned for small distances.

  • The first formula I mention will be implemented and we can write some explanations about that in README.

What do you think about that? Thanks.

@peter279k
Copy link
Contributor Author

@DivineOmega, any thought about this :)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants