Sphärischer Abstand: Unterschied zwischen den Versionen

Aus Wiki
Wechseln zu: Navigation, Suche
 
K (Spherische Abstand wurde nach Sphärischer Abstand verschoben)
 
(2 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
Haversine formula:
+
Haversine formula:
 
 
  
R = earth’s radius (mean radius = 6,371km)
+
R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
+
Δlat = lat2− lat1
Δlong = long2− long1
+
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
+
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
+
c = 2.atan2(√a, √(1−a))
d = R.c
+
d = R.c
  
(Note that angles need to be in radians to pass to trig functions).
+
(Note that angles need to be in radians to pass to trig functions).
JavaScript:
+
JavaScript:
  
var R = 6371; // km
+
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
+
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();  
+
var dLon = (lon2-lon1).toRad();  
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
+
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
 
         Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *  
 
         Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *  
 
         Math.sin(dLon/2) * Math.sin(dLon/2);  
 
         Math.sin(dLon/2) * Math.sin(dLon/2);  
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));  
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));  
var d = R * c;
+
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;

Aktuelle Version vom 20. Juli 2012, 16:10 Uhr

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;