root/lib/angles.py @ 9302
1 |
# Angles
|
---|---|
2 |
|
3 |
rev_deg = 360 |
4 |
|
5 |
compass_dir_headings = {'N': 0, 'E': 90, 'S': 180, 'W': 270} |
6 |
|
7 |
def compass2heading(compass): |
8 |
heading = None |
9 |
for dir_ in reversed(compass): |
10 |
dir_heading = compass_dir_headings[dir_] |
11 |
if heading == None: heading = dir_heading |
12 |
else: |
13 |
sum_ = dir_heading + heading |
14 |
if abs(dir_heading - heading) > rev_deg/2: sum_ += rev_deg |
15 |
heading = sum_/2. % rev_deg |
16 |
return heading |