初始速度:u
与地面的角度:theta
水平速度:ux = u * cos(theta)
垂直速度:uy = u * sin(theta) - gt
水平距离:sx = ux * t = u * cos(theta) * t
垂直距离:sy = uy * t - 0.5 * g * t * t = u * sin(theta) * t - 0.5 * t * t
最高点时,uy = 0, u * sin(theta) = gt, t = u * sin(theta) / g
总时间 = 2 * t = 2 * u * sin(theta) / g
import math
import numpy as np
import matplotlib.pyplot as plt
def draw_graph(x, y):
plt.plot(x, y)
plt.xlabel('x-coordinate')
plt.ylabel('y-coordinate')
plt.title('Projectile motion of a ball')
def draw_trajectory(u, theta):
theta = math.radians(theta)
g = 9.8
# 总持续时间
t_flight = 2 * u * math.sin(theta) / g
intervals = np.arange(0, t_flight, 0.001)
x = []
y = []
for t in intervals:
x.append(u * math.cos(theta) * t)
y.append(u * math.sin(theta) * t - 0.5 * g * t * t)
draw_graph(x, y)
if __name__ == '__main__':
u_list = [20, 40, 60]
theta = 60
for u in u_list:
draw_trajectory(u, theta)
plt.legend(['20', '40', '60'])
plt.show()