feat: add drawing trajectory

This commit is contained in:
2025-04-15 12:32:56 +03:00
parent a43e56cef3
commit e606b841a9
4 changed files with 77 additions and 19 deletions

43
random_pilot.py Normal file
View File

@@ -0,0 +1,43 @@
import math
import random
# 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 = 500
points = [point.copy()]
for i in range(iter_count):
dx, dy = randomPilot.step()
point[0] += dx
point[1] += dy
points.append(point.copy())
print(*zip(*points))
plt.plot(*zip(*points), '--')
plt.show()
if __name__ == '__main__':
_test()