source: subversion/applications/routing/pyroute/geometry.py @ 5649

Last change on this file since 5649 was 5498, checked in by ojw, 12 years ago

reading geonames (gets XML from a file at the moment, instead of
downloading it)

File size: 665 bytes
Line 
1import math
2
3def bearing(a,b):
4    dlat = math.radians(b[0] - a[0])
5    dlon = math.radians(b[1] - a[1])
6
7    dlon = dlon * math.cos(math.radians(a[0]))
8   
9    return(math.degrees(math.atan2(dlon, dlat)))
10
11def distance(a,b):
12    dlat = math.radians(a[0] - b[0])
13    dlon = math.radians(a[1] - b[1])
14
15    dlon = dlon * math.cos(math.radians(a[0]))
16    #print "d = %f, %f" % (dlat, dlon)
17    # todo: mercator proj
18    dRad = math.sqrt(dlat * dlat + dlon * dlon)
19
20    c = 40000 # earth circumference,km
21   
22    return(dRad * c)
23   
24
25if(__name__ == "__main__"):
26    a = (51.477,-0.4856)
27    b = (51.477,-0.4328)
28
29    print bearing(a,b)
Note: See TracBrowser for help on using the repository browser.