Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Adds Haversine formula class #39
The Haversine formula is used to determine the distance between two points on a sphere (e.g., the Earth).
Simply pass a pair of to/from arrays containing the latitude and longitude of the points and you can calculate the distance in meters, miles, and kilometres.
You can, of course, extend this to use the radius of a different sphere, such as another planet or an arbitrary spherical model.
Here's a usage example, determining the distance from Land's End to John O'Groats as the crow flies:
Haversine::make([50.0657, 5.7132], [58.6373, 3.0689])->meters(); // 968205.89737109 Haversine::make([50.0657, 5.7132], [58.6373, 3.0689])->kilometers(); // 968.20589737109 Haversine::make([50.0657, 5.7132], [58.6373, 3.0689])->miles(); // 601.61525278069