Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. print("nTo calculate the components of a projectile fired at an angle")
  2. print("We need the angle(degrees), the initial velocity(ms-1), and")
  3. print("The gravity constant (9.81 on earth)n")
  4. angle_0 = float(input("Please enter the angle you want it to be fired at: "))
  5. angle_0 = (angle_0)/180.0*np.pi
  6. height = float(input("nPlease enter the starting height for the projectile: "))
  7. speed = float(input("nPlease enter the initial velocity you want it to be fired atn In metres per second: "))
  8. g=9.81
  9. plt.figure()
  10. time_max = ((2 * speed) * np.sin(angle_0)) / g
  11. time = time_max*np.linspace(0,1,100)[:,None]
  12. x_values = ((speed * time) * np.cos(angle_0))
  13. y_values = ((speed * time) * np.sin(angle_0)) - ((0.5 * g) * (time ** 2))
  14. distance_x = (speed * np.cos(angle_0))*time_max
  15. plt.plot(x_values,[i+(height) for i in y_values], linewidth = 1.5)
  16. plt.ylim([0,1000])
  17. plt.xlim([0,1000])
  18. plt.show()
  19. print("")
  20. print ("The Range of this projectile will be, "+str(distance_x))
  21. print ("")
  22. for x, y in zip(y_values, x_values):
  23. if x == 0 or y == 0:
  24. print(x, y)
  25. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement