# лаба 2 моделирование работает

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75``` ```__author__ = 'Lenovo' import math from math import pi import numpy as np import matplotlib.pyplot as plt def makePath(alpha, v0, k, eps, xmax, ymax): # print alpha alpha = math.radians(alpha) # print alpha vx = v0 * np.cos(alpha) vy = v0 * np.sin(alpha) xcur = xmax*0.5 ycur = ymax*0.5 while vx**2 + vy**2 > eps: plt.bar(0, ymax, xmax, 0, color = 'w') #plt.show() if alpha <= pi/2: if ycur + (xmax - xcur) * np.tan(alpha) > ymax: #top t1 = np.linspace(xcur, xcur + (ymax - ycur)/ np.tan(alpha), 2) plt.plot(t1, np.tan(alpha)*t1 + ycur - xcur*np.tan(alpha)) xcur = xcur + abs((ymax - ycur)/ np.tan(alpha)) ycur = ymax alpha = 2*pi - alpha else: #right t1 = np.linspace(xcur, xmax, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur - xcur*np.tan(alpha)) ycur = ycur + xmax * np.tan(alpha)- xcur*np.tan(alpha) xcur = xmax alpha = pi - alpha elif alpha <= pi: if ycur + abs(xcur * np.tan(alpha)) > ymax: #top t1 = np.linspace(xcur - abs((ymax - ycur)/ np.tan(alpha)), xcur, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur + abs(xcur * np.tan(alpha))) xcur = xcur - abs((ymax - ycur)/ np.tan(alpha)) ycur = ymax alpha = 2*pi - alpha else: #left t1 = np.linspace(0, xcur, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur + abs(xcur * np.tan(alpha))) ycur = ycur + abs(xcur * np.tan(alpha)) xcur = 0 alpha = pi - alpha elif alpha <= 3*pi/2: if ycur - abs(xcur * np.tan(alpha)) < 0: #bottom t1 = np.linspace(xcur - abs(ycur/ np.tan(alpha)), xcur, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur - abs(xcur * np.tan(alpha))) xcur = xcur - abs(ycur/ np.tan(alpha)) ycur = 0 alpha = 2*pi - alpha else: #left t1 = np.linspace(0, xcur, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur - abs(xcur * np.tan(alpha))) ycur = ycur - abs(xcur * np.tan(alpha)) xcur = 0 alpha = 3*pi - alpha else: if ycur - abs((xmax - xcur) * np.tan(alpha)) < 0: #bottom t1 = np.linspace(xcur, xcur + abs(ycur/ np.tan(alpha)), 2) plt.plot(t1, np.tan(alpha)*t1 + ycur + abs(xcur * np.tan(alpha))) xcur = xcur + abs(ycur/ np.tan(alpha)) ycur = 0 alpha = 2*pi - alpha else: #right t1 = np.linspace(xcur, xmax, 2) plt.plot(t1, np.tan(alpha)*t1 + ycur + abs(xcur * np.tan(alpha))) ycur = ycur - abs((xmax - xcur) * np.tan(alpha)) xcur = xmax alpha = 3*pi - alpha vx = vx*k vy = vy*k plt.show() makePath(300, 20, 0.9, 0.1, 20, 40) ```