Files
autopilot/random_pilot.py

45 lines
1.1 KiB
Python

import math
import random
from time import sleep
# from scipy import
from matplotlib import pyplot as plt
class RandomPilot():
angle: float
def __init__(self, velocity: float = 1):
self.dangle = 0
self.angle = random.random() * math.pi * 2
self.velocity = velocity
def step(self) -> tuple[float, float]:
# Поворот угла траектории
self.dangle += (random.random() - 0.5) * 0.1
self.dangle = max(min(self.dangle, 0.2), -0.2)
self.angle += self.dangle
dx = math.cos(self.angle) * self.velocity
dy = math.sin(self.angle) * self.velocity
return dx, dy
def _test():
randomPilot = RandomPilot()
point = [0, 0]
iter_count = 250
points = [point.copy()]
plt.axis([-100, 100, -100, 100])
# plt.
for i in range(iter_count):
dx, dy = randomPilot.step()
prev_point = point.copy()
point[0] += dx
point[1] += dy
points.append(point.copy())
plt.plot(*zip(*points[-2:]), color='#5e5')
plt.pause(0.025)
sleep(1)
if __name__ == '__main__':
_test()