tipc21/alrys/test.py

49 lines
981 B
Python

import sys
from math import atan2, hypot, pi, cos, sin
from alryslib import *
if len(sys.argv) != 2:
print('Usage: python.exe test.py input_file')
sys.exit(1)
buffer = ''
try:
with open(sys.argv[1], 'r') as f:
buffer = f.read()
except IOError:
print('Cannot open %s' % sys.argv[1])
sys.exit(1)
steps = []
for e in buffer.split():
try:
steps.append(float(e))
except:
pass
x, a, y, b = steps[4:8]
x += a * 1e-14
y += b * 1e-14
position = [x, y, 0]
index = 8
def mon_itineraire():
global steps, position, index
x, a, y, b = steps[index:index + 4]
x += a * 1e-14
y += b * 1e-14
a = atan2(y - position[1], x - position[0]) * 180.0 / pi - position[2]
l = hypot(x - position[0], y - position[1])
a_droite(a)
en_avant(l)
position[2] += a
position[0] += l * cos(position[2] * pi / 180.0)
position[1] += l * sin(position[2] * pi / 180.0)
index += 4
return index < len(steps) - 3
print(aller_selon(mon_itineraire, steps[0:8]))