Open peter279k opened 5 years ago
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.
@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:
And the distance is: (r
is the $greatCircleRadius
value)
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:
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?
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.
@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.
@DivineOmega, any thought about this :)?
Please refer this: https://en.wikipedia.org/wiki/Great-circle_distance