Advertisement
thienclone

Untitled

Apr 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pylab as plot
  3. import math as m
  4. #initialize variables
  5. #velocity, gravity
  6. v = 30
  7. g = 9.8
  8. #increment theta 25 to 60 then find t, x, y
  9. #define x and y as arrays
  10.  
  11. theta = np.arange(m.pi/6, m.pi/3, m.pi/36)
  12.  
  13. t = np.linspace(0, 5, num=100) # Set time as 'continous' parameter.
  14.  
  15. for i in theta: # Calculate trajectory for every angle
  16. x1 = []
  17. y1 = []
  18. for k in t:
  19. x = ((v*k)*np.cos(i)) # get positions at every point in time
  20. y = ((v*k)*np.sin(i))-((0.5*g)*(k**2))
  21. x1.append(x)
  22. y1.append(y)
  23. p = [i for i, j in enumerate(y1) if j < 0] # Don't fall through the floor
  24. for i in sorted(p, reverse = True):
  25. del x1[i]
  26. del y1[i]
  27.  
  28. plot.plot(x1, y1) # Plot for every angle
  29.  
  30. plot.show() # And show on one graphic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement