导入matplotlib.pyplot作为plt
将numpy导入为np
导入数学
导入matplotlib.gridspec作为gridspec
从matplotlib.animation导入FuncAnimation
无花果= plt.figure()
plt.xlabel('X')
plt.ylabel('Y')
ylim(0,10)
plt.xlim(0,10)
def xy_plot1(u,theta):
y_arr1= []
x_arr1 = []
# displacement in the y_direction is zero
x_disp = (u*u)*(math.sin(2*theta))/9.8 # disp_x = (u^2)*sin(2theta)/g {horizontal range}
x = 0 # distance from the origin
while(x <= x_disp):
# below is the equation of path of projectile
y = (x*(math.tan(theta))) - ((9.8*x*x)/(2*pow((u*math.cos(theta)), 2)))
y_arr1.append(y)
x_arr1.append(x)
x = x + 0.1 # basically x = x + dx
plt.plot(x_arr1, y_arr1)
def xy_plot2(u,theta):
y_arr2 = []
x_arr2 = []
# displacement in the y_direction is zero
x_disp = (u*u)*(math.sin(2*theta))/9.8 # disp_x = (u^2)*sin(2theta)/g {horizontal range}
x = 0 # distance from the origin
dx = 0.1
while(x <= x_disp):
# below is the equation of path of projectile
y = (x*(math.tan(theta))) - ((9.8*x*x)/(2*pow((u*math.cos(theta)), 2)))
y_arr2.append(y)
x_arr2.append(x)
x = x + dx
plt.plot(x_arr2, y_arr2)
xy_plot1(10,60)
xy_plot2(10,30)
plt.show()
小心!xyplot()函数的theta参数以度为单位,但是在函数内部,math.sin()函数采用以弧度为单位的角度参数。最简单的解决方法是以弧度而不是度为单位提供theta参数。
如果它们确实做同样的事情,那么您也不需要这两个函数,因为plt.plot()会在不清除绘图的情况下绘制后续的弹丸曲线以及先前的弹丸曲线。
import matplotlib.pyplot as plt
import numpy as np
import math
import matplotlib.gridspec as gridspec
from matplotlib.animation import FuncAnimation
fig = plt.figure()
plt.xlabel('X')
plt.ylabel('Y')
# limiting the y and x axis
plt.ylim(0, 10)
plt.xlim(0, 10)
def xy_plot(u, theta):
y_arr2 = []
x_arr2 = []
# displacement in the y_direction is zero
x_disp = (u*u)*(math.sin(2*theta))/9.8 # disp_x = (u^2)*sin(2theta)/g {horizontal range}
x = 0 # distance from the origin
dx=0.1
while(x <= x_disp):
# below is the equation of path of projectile
y = (x*(math.tan(theta))) - ((9.8*x*x)/(2*pow((u*math.cos(theta)), 2)))
y_arr2.append(y)
x_arr2.append(x)
x = x + dx
plt.plot(x_arr2, y_arr2)
# be careful about using degrees versus radians!!
xy_plot(10, math.pi/3)
xy_plot(10, math.pi/6)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句