feat: add drawing trajectory
This commit is contained in:
43
random_pilot.py
Normal file
43
random_pilot.py
Normal 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()
|
||||
Reference in New Issue
Block a user