-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakegrid.py
More file actions
101 lines (73 loc) · 3.38 KB
/
Copy pathmakegrid.py
File metadata and controls
101 lines (73 loc) · 3.38 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import argparse
import math
import geopy.distance
def generate_hive_locations(current_location, step_distance,
step_limit, radius):
NORTH = 0
EAST = 90
SOUTH = 180
WEST = 270
xdist = math.sqrt(3) * step_distance # Distance between column centers.
ydist = 3 * (step_distance / 2) # Distance between row centers.
results = []
results.append((current_location[0], current_location[1], 0))
loc = current_location
ring = 1
while ring <= radius:
loc = get_new_coords(loc, ydist * (step_limit - 1), NORTH)
loc = get_new_coords(loc, xdist * (1.5 * step_limit - 0.5), EAST)
results.append((loc[0], loc[1], 0))
for i in range(ring):
loc = get_new_coords(loc, ydist * step_limit, NORTH)
loc = get_new_coords(loc, xdist * (1.5 * step_limit - 1), WEST)
results.append((loc[0], loc[1], 0))
for i in range(ring):
loc = get_new_coords(loc, ydist * (step_limit - 1), SOUTH)
loc = get_new_coords(loc, xdist * (1.5 * step_limit - 0.5), WEST)
results.append((loc[0], loc[1], 0))
for i in range(ring):
loc = get_new_coords(loc, ydist * (2 * step_limit - 1), SOUTH)
loc = get_new_coords(loc, xdist * 0.5, WEST)
results.append((loc[0], loc[1], 0))
for i in range(ring):
loc = get_new_coords(loc, ydist * (step_limit), SOUTH)
loc = get_new_coords(loc, xdist * (1.5 * step_limit - 1), EAST)
results.append((loc[0], loc[1], 0))
for i in range(ring):
loc = get_new_coords(loc, ydist * (step_limit - 1), NORTH)
loc = get_new_coords(loc, xdist * (1.5 * step_limit - 0.5), EAST)
results.append((loc[0], loc[1], 0))
# Back to start.
for i in range(ring - 1):
loc = get_new_coords(loc, ydist * (2 * step_limit - 1), NORTH)
loc = get_new_coords(loc, xdist * 0.5, EAST)
results.append((loc[0], loc[1], 0))
loc = get_new_coords(loc, ydist * (2 * step_limit - 1), NORTH)
loc = get_new_coords(loc, xdist * 0.5, EAST)
ring += 1
return results
# Returns destination coords given origin coords, distance (Kms) and bearing.
def get_new_coords(init_loc, distance, bearing):
"""
Given an initial lat/lng, a distance(in kms), and a bearing (degrees),
this will calculate the resulting lat/lng coordinates.
"""
origin = geopy.Point(init_loc[0], init_loc[1])
destination = geopy.distance.distance(meters=distance).destination(
origin, bearing)
return (destination.latitude, destination.longitude)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('latitude', type=float, help='starting latitude')
parser.add_argument('longitude', type=float, help='starting longitude')
parser.add_argument("-r", "--radius", type=int, default=10,
help='radius of hexagon')
parser.add_argument("-d", "--distance", type=int, default=5,
help='separation between points (meters)')
args = parser.parse_args()
results = generate_hive_locations((args.latitude, args.longitude),
args.distance, 1, args.radius)
for point in results:
print("{},{}".format(point[0], point[1]), flush=True)
if __name__ == "__main__":
main()