-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py
executable file
·102 lines (80 loc) · 1.96 KB
/
grid.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
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
102
#!/usr/bin/env python2
import argparse
import math
import numpy as np
import numpy.linalg as la
from scipy import interpolate
from mortarlib import GridRef
from mortarlib.errors import Error
NORTH = np.array([0, -100])
ranges = np.arange(50, 1251, 50)
mils = np.array([
1579,
1558,
1538,
1517,
1496,
1475,
1453,
1431,
1409,
1387,
1364,
1341,
1317,
1292,
1267,
1240,
1212,
1183,
1152,
1118,
1081,
1039,
988,
918,
800
])
interp_mils = interpolate.interp1d(ranges, mils)
mils_spline = interpolate.splrep(ranges, mils)
def get_angle(to_target):
angle = math.degrees(np.arctan2(to_target[0], -to_target[1]))
if angle < 0:
return 360 + angle
else:
return angle
def get_elevation_lerp(dist):
return float(interp_mils(dist))
def get_elevation_spline(dist):
reachable = dist >= 50 and dist <= 1250
return reachable, float(interpolate.splev(dist, mils_spline))
def get_range(to_target):
return la.norm(to_target)
def calculate(base, target):
to_target = target - base
angle = get_angle(to_target)
distance = get_range(to_target)
reachable, elev = get_elevation_spline(distance)
print
print "Targeting solution"
print "-------------------------------"
print "Angle : {:>10.1f} degrees".format(angle)
print "Distance : {:>10.1f} meters".format(distance)
if reachable:
print "Elevation : {:>10.1f} mils".format(elev)
else:
print "Elevation : N/A"
print
print "Ready to fire!"
print
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('base')
parser.add_argument('target')
args = parser.parse_args()
try:
base = GridRef.from_string(args.base)
target = GridRef.from_string(args.target)
calculate(base.vector, target.vector)
except Error as e:
print "Something went wrong: {}".format(e)