Я хотел знать, есть ли способ преобразовать этот код в код np.array. затем добавьте его в ссылку. Я хотел добавить угол, с которого мяч вылетает.
import numpy as np
import scipy as sp
from scipy.integrate import ode
import matplotlib.pylab as pl
import matplotlib.pyplot as plt
import math
from matplotlib import*
from matplotlib.pyplot import *
from __future__ import division
import math
def projectile_xy(initPos,g,initVel):
data_xy = []
initTime = 0.0
while True:
теперь вычисляем высоту y
y = initPos + (initTime * initVel * math.sin(theta)) - (g * initTime * initTime)/2
снаряд достиг уровня земли
if y < 0:
break
рассчитать расстояние х
x = initVel * math.cos(theta) * initTime
добавить кортеж (x, y) в список
data_xy.append((x, y))
используйте время с шагом 0,1 секунды
initTime += 0.1
return data_xy
g = 9.8
#h = float(raw_input("Enter the height "))
initPos = float(raw_input("Enter the height "))
der = float(raw_input("Enter the angle "))
#v = float(raw_input("Enter velocity "))
initVel = float(raw_input("Enter velocity "))
theta = math.radians(der) # radians
data_der = projectile_xy(initPos,g,initVel)
найти максимальную высоту...
point_height_max = max(data_der, key = lambda q: q[1])
xm, ym = point_height_max
x_max = max(data_der)[0]
print('''
Projectile Motion ...
Using a firing angle of {} degrees
and a muzzle velocity of {} meters/second
the maximum height is {:0.1f} meters
at a distance of {:0.1f} meters'''.format(der, initVel, ym, xm))
print "maximum distance" ,(x_max)
Введите высоту 1 Введите угол 45 Введите скорость 30
Projectile Motion ...
Using a firing angle of 45.0 degrees
and a muzzle velocity of 30.0 meters/second
the maximum height is 24.0 meters
at a distance of 46.7 meters
maximum distance 91.2167747731