-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile_graphic.py
More file actions
68 lines (54 loc) · 1.98 KB
/
projectile_graphic.py
File metadata and controls
68 lines (54 loc) · 1.98 KB
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
import matplotlib.pyplot as plt
import numpy as np
import math
from mpl_toolkits.mplot3d import Axes3D
def projectile_graphic():
g = 9.80665
dt = 0.1
t = 0
angle = list(map(float,input("각도들(°)(공백으로 구분): ").split()))
throw_v = float(input("초기 속도(m/s): "))
xz = float(input("xz평면에 내린 수선의 발과 원점을 이은 직선과 x축이 이루는 각도(°): "))
trajectories = [[(0, 0, 0)] for _ in range(len(angle))]
dones = np.zeros_like(angle, dtype=bool)
all_done = False
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
while not all_done:
ax.cla()
ax.set_title("projectile movement")
#ax.set_xlim(-1, 600)
#ax.set_ylim(-1, 600)
#ax.set_zlim(-1, 600)
for i in range(len(angle)):
x, y, z = zip(*trajectories[i])
ax.scatter(x, z, y, label=angle[i])
ax.legend()
t = t + dt
for i in range(len(angle)):
last_x, last_y, last_z = trajectories[i][-1]
w = angle[i]
v_x_z= throw_v * np.cos(w/180*np.pi)
throw_v_x = v_x_z* np.cos(xz/180*np.pi)
throw_v_y = throw_v * np.sin(w/180*np.pi)
throw_v_z = v_x_z* np.sin(xz/180*np.pi)
if throw_v_x<0.00000000001:
throw_v_x=0
if throw_v_z<0.00000000001:
throw_v_z=0
next_x = throw_v_x * t
next_y = throw_v_y * t - 0.5 * g * t**2
next_z = throw_v_z * t
if next_y <= 0:
dones[i] = True
#print(i,t)
continue
trajectories[i].append((next_x, next_y, next_z))
all_done = dones.all()
plt.pause(0.1*dt)
#print(t)
for i in range(len(angle)):
print(f"{angle[i]}도로 던졌을 때 간 거리: {((trajectories[i][-1][0]**2+trajectories[i][-1][2]**2)**(1/2)):.2f}m")
plt.show()
if __name__ == '__main__':
projectile_graphic()