当互补角度(例如 30 和 60)传递给 xy_plot1 和 xyplot2 函数时,两个射弹的图形无法正常工作
the graphs of the two projectiles does not work properly when complementary angles(eg 30 and 60) are passes to xy_plot1 and xyplot2 function
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_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()
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_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()