【发布时间】:2016-03-17 21:43:14
【问题描述】:
我正在尝试以不同的角度绘制弹丸随时间变化的图形。角度范围从 25 到 60,每个初始角度在图表上应该有自己的线。 “弹丸在空中的总时间”的公式是 t 的公式。我不确定这个总时间是如何发挥作用的,因为我应该以不同的初始角度绘制不同时间的弹丸。我想我需要 x,x1,x2,x3,x4,x5 和 y 等价物来绘制所有六个不同角度的图形。但我很困惑如何处理所花费的时间。
import numpy as np
import matplotlib.pylab as plot
#initialize variables
#velocity, gravity
v = 30
g = -9.8
#increment theta 25 to 60 then find t, x, y
#define x and y as arrays
theta = np.arange(25,65,5)
t = ((2 * v) * np.sin(theta)) / g #the total time projectile remains in the #air
t1 = np.array(t) #why are some negative
x = ((v * t1) * np.cos(theta))
y = ((v * t1) * np.sin(theta)) - ((0.5 * g) * (t ** 2))
plot.plot(x,y)
plot.show()
【问题讨论】:
-
np.cos和它的表亲np.sin和其他人期望以弧度为单位的角度,所以首先将theta与np.pi / 180相乘或使用np.radians()。此外,无需将t转换为np.array t1,因为它已经是一个 numpy 数组。
标签: python numpy matplotlib