我正在用Python模拟多角度的弹丸运动。这是一个几乎完成的代码,除了我还需要显示每个射弹的射程。你知道我该怎么做吗
import numpy as np
import matplotlib.pyplot as plt
import math
#theta=pi/3
V=38.5 #speed
t=np.arange(0,19,0.1)
angle = math.pi/12
angle_list=[]
while angle < math.pi/2:
x=V*np.cos(angle)*t
y=V*np.sin(angle)*t+(0.5*-9.8*t**2)
plt.ylim([0,80])
plt.xlim([0,170])
print(x,y)
plt.plot(x,y)
angle_list.append(rf'{np.rad2deg(angle):.0f}$\degree$')
angle+=math.pi/12
plt.xlabel("range")
plt.ylabel("height")
plt.title('Projectile Motion With Multiple Angles')
plt.legend(angle_list)
plt.show()
图表的图片:
您只需要找到零交叉点,即
x
的最大值,该值为y > 0
,并提供可用于注释图形的范围,如下所示-相关问题 更多 >
编程相关推荐