Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Haversine Formula or the Vincenty's Formula better for calculating distance?

Which is better for calculating the distance between two latitude/longitude points, The Haversine Formula or The Vincenty's Formula? Why?

The distance is obviously being calculated on Earth. Does WGS84 vs GCJ02 coordinates impact the calculation or distance (The Vincenty's formula takes the WGS84 axis into consideration)?

For example, in Android, the Haversine Formula is used in Google Map Utils, but the Vincenty Formula is used by the android.Location object (Location.distanceBetween()).

like image 455
jjNford Avatar asked Jul 07 '16 14:07

jjNford


People also ask

Which formula should we use in calculating distance?

distance = speed × time. time = distance ÷ speed.

Does haversine formula work for small distances?

The haversine formula is a re-formulation of the spherical law of cosines, but the formulation in terms of haversines is more useful for small angles and distances.

What is the haversine formula used for?

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical triangles.


2 Answers

Haversine and Vincenty are two algorithms for solving different problems. Haversine computes the great circle distance on a sphere while Vincenty computes the shortest (geodesic) distance on the surface of an ellipsoid of revolution. So the answer to your question can be broken into 2 parts:

  1. Do you want to compute the distance on a sphere on an ellipsoid?
  2. How accurate is Haversine or Vincenty at calculating the given problem?

For terrestrial applications, an ellipsoid of revolution is a reasonable approximation to "mean sea level"; the error is ± 100 m. The flattening of this ellipsoid is small, about 1/300, and so can be approximated by a sphere (of equal volume, for example).

Great circle distances differ from geodesic distances by up to 0.5%. In some applications, e.g., what's the distance from the Cape to Cairo?, this error can be neglected. In other applications, e.g., determining maritime boundaries, it is far too large (it's 5 m over a distance of 1 km). In general, you're safer using the geodesic distance.

If you're interested is distance traveled (by car, boat, or plane), there are lots of constraints on the path taken and neither the great circle or geodesic distance, which measure the length of shortest paths on an ideal surface, would be appropriate.

On the question of whether the algorithms are accurate:

Haversine is accurate to round-off unless the points are nearly antipodal. Better formulas are given in the Wikipedia article on great-circle distances.

Vincenty is usually accurate to about 0.1 mm. However if the points are nearly antipodal, the algorithm fails to converge and the error is much larger. I give a better algorithm for solving the geodesic problem in Algorithms for geodesics. See also the Wikipedia article on geodesics on an ellipsoid.

Solving the geodesic problem is slower than solving for the great-circle. But it's still very fast (about 1 μs per calculation), so this shouldn't be a reason to prefer great circle distances.

ADENDUM

Here is the Java package which implements my algorithm for finding geodesic distances. Unlike Vincenty's method, this is accurate to round-off and converges everywhere.

like image 166
cffk Avatar answered Sep 19 '22 19:09

cffk


Haversine is a simpler computation but it does not provide the high accuracy Vincenty offers.

Vincenty is more accurate but is also more computationally intensive and will therefore perform slower and increase battery usage.

As with anything "better" is a matter of your particular application. For your application, Vincenty may be a "better" choice than Haversine, but for a different application, Haversine may be a better choice. You will have to look at the particulars of your use cases and make a determination based upon what you find there.

like image 26
andand Avatar answered Sep 18 '22 19:09

andand