The Haversine formula calculates the shortest distance between two points on a sphere using their latitudes and longitudes measured along the surface. It is important for use in navigation. The haversine can be expressed in trignometric function as:
The haversine of the central angle (which is d/r) is calculated by the following formula:
where r is the radius of earth(6371 km), d is the distance between two points, is latitude of the two points and is longitude of the two points respectively.
Solving d by applying the inverse haversine or by using the inverse sine function, we get:
The distance between Big Ben in London (51.5007° N, 0.1246° W) and The Statue of Liberty in
New York (40.6892° N, 74.0445° W) is 5574.8 km. This is not the exact measurement because the
formula assumes that the Earth is a perfect sphere when in fact it is an oblate spheroid.
Below is the implementation of the above formulae:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find points at a given distance on a line of given slope
- Find the maximum possible distance from origin using given points
- Find the integer points (x, y) with Manhattan distance atleast N
- Find integral points with minimum distance from given set of integers using BFS
- Ways to choose three points with distance between the most distant points <= L
- Hammered distance between N points in a 2-D plane
- Program to calculate distance between two points in 3 D
- Program to calculate distance between two points
- Program for distance between two points on earth
- Check whether it is possible to join two points given on circle such that distance between them is k
- Sort an Array of Points by their distance from a reference Point
- Legendre's formula (Given p and n, find the largest x such that p^x divides n!)
- Steps required to visit M points in order on a circular ring of N points
- Minimum number of points to be removed to get remaining points on one side of axis
- Find K Closest Points to the Origin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.