124
社区成员




第三题
已知某型迫击炮发射初速度为300m/s
, 炮弹飞行过程中无动力,不考虑空气阻力,重力加速度取9.8m2/s
。在不同的角度下,炮弹落地的时间与飞行的位置都不一样。本题通过编程绘制角度分别为[30, 45, 60, 75]
度时的炸弹轨迹。其中函数calBombT\frace(theta)
计算炮弹飞行过程中n
个位置坐标,时间样本为均匀分配。你的任务是补充完整该程序代码。
计算逻辑示例如下(编程时不需要取整):
当角度为为30
度时,炸弹空中飞行时间约为30.6s
,
若取5
个均匀的时间样本,分别约为[ 0, 7.6, 15.3, 22.9, 30.6 ]
则对应的x
坐标则为[0,1988, 3976, 5964, 7953]
对应的y
坐标则为[ 0, 860,1147, 860, 0 ]
代码实现
def calBombTrace(theta):
v0, g, n = 300, 9.8, 30
theta_d = np.radians(theta) #因numpy中cos、sin的输入为弧度值,故先将theta从度转换为弧度
v0_x = v0*np.cos(theta_d) #炮弹水平初速度
v0_y = v0*np.sin(theta_d) #炮弹垂直初速度
tmax = 2*v0_y/g #落地时间,即v0_y*t-0.5gtt=0的解
t = np.linspace(0, tmax, n) #n个时刻
xt = v0_x*t #n个时刻的横坐标
yt = v0_y*t-1/2*g*t**2 #n个时刻的纵坐标
return xt, yt
for theta in [30, 45, 60, 75]:
# 调用函数,得到theta返回的值,并存储到xt与yt变量
xt,yt=calBombTrace(theta)
plt.plot(xt, yt)
plt.grid('on')
plt.axis([0, 10000, 0, 5000])
plt.savefig('./src/step4/res/轨迹.png')
plt.close()
print([round(x,6) for x in xt])
print([round(x,6) for x in yt])