-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize_path.py
49 lines (41 loc) · 1.62 KB
/
visualize_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
import dijkstra
import nhpn
from math import *
def flat_earth(filename = 'path_flat.kml'):
"""Test long path"""
nodes, links = dijkstra.load_data()
dijkstra.create_adjacency_lists(nodes, links)
source = dijkstra.node_by_name(nodes, 'PASADENA', 'CA')
destination = dijkstra.node_by_name(nodes, 'CAMBRIDGE', 'MA')
ans = dijkstra.shortest_path(nodes,
links,
dijkstra.distance,
source,
destination)
nhpn.Visualizer.toKML(ans, 'path_flat.kml')
print "path_flat.kml created"
def curved_earth(filename = 'path_curved.kml'):
"""Test long path"""
nodes, links = dijkstra.load_data()
dijkstra.create_adjacency_lists(nodes, links)
def distance(node1, node2):
"""Returns the distance between node1 and node2, including the
Earth's curvature."""
A = node1.latitude*pi/10**6/180
B = node1.longitude*pi/10**6/180
C = node2.latitude*pi/10**6/180
D = node2.longitude*pi/10**6/180
return acos(sin(A)*sin(C)+cos(A)*cos(C)*cos(B-D))
source = dijkstra.node_by_name(nodes, 'PASADENA', 'CA')
destination = dijkstra.node_by_name(nodes, 'CAMBRIDGE', 'MA')
ans = dijkstra.shortest_path(nodes,
links,
distance,
source,
destination)
nhpn.Visualizer.toKML(ans, 'path_curved.kml')
print "path_curved.kml created"
if __name__ == '__main__':
flat_earth()
curved_earth()