March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
13
Task/Haversine-formula/AutoHotkey/haversine-formula.ahk
Normal file
13
Task/Haversine-formula/AutoHotkey/haversine-formula.ahk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
MsgBox, % GreatCircleDist(36.12, 33.94, -86.67, -118.40, 6372.8, "km")
|
||||
|
||||
GreatCircleDist(La1, La2, Lo1, Lo2, R, U) {
|
||||
return, 2 * R * ASin(Sqrt(Hs(Rad(La2 - La1)) + Cos(Rad(La1)) * Cos(Rad(La2)) * Hs(Rad(Lo2 - Lo1)))) A_Space U
|
||||
}
|
||||
|
||||
Hs(n) {
|
||||
return, (1 - Cos(n)) / 2
|
||||
}
|
||||
|
||||
Rad(Deg) {
|
||||
return, Deg * 4 * ATan(1) / 180
|
||||
}
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
>>> import math
|
||||
>>> def haversine(lat1, lon1, lat2, lon2):
|
||||
R = 6372.8
|
||||
# In kilometers
|
||||
dLat = math.radians(lat2 - lat1)
|
||||
dLon = math.radians(lon2 - lon1)
|
||||
lat1 = math.radians(lat1)
|
||||
lat2 = math.radians(lat2)
|
||||
from math import radians, sin, cos, sqrt, atan2
|
||||
|
||||
def haversine(lat1, lon1, lat2, lon2):
|
||||
|
||||
R = 6372.8
|
||||
|
||||
# In kilometers
|
||||
|
||||
dLat = radians(lat2 - lat1)
|
||||
dLon = radians(lon2 - lon1)
|
||||
lat1 = radians(lat1)
|
||||
lat2 = radians(lat2)
|
||||
|
||||
a = sin(dLat/2.)*sin(dLat/2.) + sin(dLon/2.)*sin(dLon/2.)*cos(lat1)*cos(lat2)
|
||||
c = 2.*atan2(sqrt(a),sqrt(1-a))
|
||||
|
||||
a = math.sin(dLat / 2) * math.sin(dLat / 2) + math.sin(dLon / 2) * math.sin(dLon / 2) * math.cos(lat1) * math.cos(lat2)
|
||||
c = 2 * math.asin(math.sqrt(a))
|
||||
return R * c
|
||||
|
||||
>>> haversine(36.12, -86.67, 33.94, -118.40)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue