DivineOmega / php-distance

Allows for calculation of many types of distance between points
GNU Lesser General Public License v3.0
4 stars 3 forks source link

Implement Great-circle distance #7

Open peter279k opened 5 years ago

peter279k commented 5 years ago

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

DivineOmega commented 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.

peter279k commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

@DivineOmega, thank you for your reply.

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

What do you think about that? Thanks.

peter279k commented 5 years ago

@DivineOmega, any thought about this :)?