You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* This Class implements the Haversine formula to calculate the distance between two points on a sphere (like Earth) from their latitudes and longitudes.
4
+
*
5
+
* The Haversine formula is used in navigation and mapping to find the great-circle distance,
6
+
* which is the shortest distance between two points along the surface of a sphere. It is often
7
+
* used to calculate the "as the crow flies" distance between two geographical locations.
8
+
*
9
+
* The formula is reliable for all distances, including small ones, and avoids issues with
10
+
* numerical instability that can affect other methods.
11
+
*
12
+
* @see "https://en.wikipedia.org/wiki/Haversine_formula" - Wikipedia
13
+
*/
14
+
publicfinalclassHaversine {
15
+
16
+
// Average radius of Earth in kilometers
17
+
privatestaticfinaldoubleEARTH_RADIUS_KM = 6371.0;
18
+
19
+
/**
20
+
* Private constructor to prevent instantiation of this utility class.
21
+
*/
22
+
privateHaversine() {
23
+
}
24
+
25
+
/**
26
+
* Calculates the great-circle distance between two points on the earth
27
+
* (specified in decimal degrees).
28
+
*
29
+
* @param lat1 Latitude of the first point in decimal degrees.
30
+
* @param lon1 Longitude of the first point in decimal degrees.
31
+
* @param lat2 Latitude of the second point in decimal degrees.
32
+
* @param lon2 Longitude of the second point in decimal degrees.
33
+
* @return The distance between the two points in kilometers.
0 commit comments