I am writing a code to plot several projectile trajectories of various theta values in Python.
theta = np.arange(np.pi/6, np.pi/3)
t = np.linspace(0,2,num=100)
while y0>=0:
for i in theta:
x = []
y = []
for k in t:
x0= v_0*np.cos(i)*k
y0= v_0*np.sin(i)*k - 1/2*g*(k**2)
x.append(x0)
x.append(y0)
After forming the arrays and putting in the necessary conditions for projectile, I have used a while loop to put the terminating instruction in the program. I think, I am missing a crucial point. Thanks!
I think you want your terminating condition inside your inner-most loop. See below, where I also defined a couple of missing constants (
v_0
,g
) and fixed onex
toy
. also printing the resultsproduces
Plotting it (y vs x), looks reasonable
It is also worth noting that your definition of
theta = np.arange(np.pi/6, np.pi/3)
looks rather strange, what are you trying to achieve here?