Sphärischer Abstand

Aus Wiki
Wechseln zu: Navigation, Suche
Haversine formula:


R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
(Note that angles need to be in radians to pass to trig functions).
JavaScript: 	
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
       Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
       Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;

In Python

R = 6371.0;
dLat = math.radians(lat2-lat1);
dLon = math.radians(lon2-lon1);
a = math.sin(dLat/2) * math.sin(dLat/2) +math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dLon/2) * math.sin(dLon/2); 
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)); 
d = R * c;