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

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

Changes from the weekend

File size: 680 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    print dRad
21    c = 40000 # earth circumference,km
22   
23    return(dRad * c)
24   
25
26if(__name__ == "__main__"):
27    a = (51.477,-0.4856)
28    b = (51.477,-0.4328)
29
30    print bearing(a,b)
Note: See TracBrowser for help on using the repository browser.