Topic: trajectory_program

I've written a trajectory_program my first attempt in Python and it works fairly well except for a couple of issues.

1. Python automaticly scales the graph and I'd like to be able to graph the tajectoies so lower angles look flater and angles higher than 45 degrees look steeper. Right now the program automaticly scales the x and y axies.

2. I'm not sure how to program the formula to refect the fact the shooter is higher than the landing zone to the projectile. As it's written now is the shooter is 5 meters above the projected ground were the round is going to land the graph doesn't extend to the ground the graph line stops 5 meters above ground level..


# trajectory_program

import matplotlib.pyplot as plt
import numpy as np
from math import pi, tan, cos, sqrt, sin
import string 

M_A=raw_input("Do you want to use Metric or American units? ")
A_M=M_A[0].lower()

theta=input("Enter the angle of tecjectory in degrees ")

if A_M == 'a':                  
   y0=float(input("Enter height in feet "))
   v0=float(input("Enter initial velocity in feet/s "))
   g=32.2
elif A_M == 'm':
   y0=float(input("Enter height in meters "))
   v0=float(input("Enter initial velocity meters/s "))
   g=9.81
else:
   print("You must choose between metric or US measures")
   metric_American()
                      
g              # gravatational constant
t=0.0          # time in flight
v0             # initial velocity
y0             # initial hight
x0 = 0         # distance 
n=100          # points
R=0.0          # Range (distance projectile travels)

theta=theta*2
sin_A=sin(theta*pi/180)
v0g=v0**2/g
R=v0g*sin_A
theta=theta/2

t=2*((v0*sin(theta*pi/180)/g))
h=((v0*sin(theta*pi/180))**2)/(2*g)


if A_M == 'a':
   print """\
   v0    = %.1f fps
   y0    = %.1f ft
   Range = %.1f ft
   Hight = %.1f ft
   duration = %.4f sec\
   """ % (v0,  y0,R, h, t)
else:
   print """\
   v0    = %.1f mps
   y0    = %.1f meters
   Range = %.1f meters
   Hight = %.1f meters
   duration = %.4f sec \
   """ % (v0,  y0,R, h, t)

theta1 = theta*pi/180
x=np.linspace(x0,R,n)
y = x*tan(theta1) - 1/(2*v0**2)*g*x**2/((cos(theta1))**2) + y0
yax=x*0
#print 'y     = %5.1f m' % (y)
plt.plot(x,y,lw=2)
plt.plot(x,yax,lw=1)
plt.xlabel("x")
plt.ylabel("y")
plt.text(0.5,0.1,r'$ v_0=%5.1f\ \  \ y_0=%5.1f\ \ \ Range=%5.1f\  \  \ Hight=%5.1f \  \ \ duration=%2.4f$' % (v0,y0,R,h, t))
plt.title("trajectory")
plt.grid(True)

plt.show()

Thumbs up