Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. #global because needs to be edited outside of function
  5. global GRAV_CONST
  6.  
  7. def projectile_motion(initial_position, angle, speed, time, color):
  8.  
  9.     #because trigonometric functions only take in radians in python
  10.     angle = np.radians(angle)
  11.    
  12.     GRAV_CONST = -9.8
  13.    
  14.     y = 0.5 * GRAV_CONST * (time ** 2) + speed * np.sin(angle) * time + initial_position[1]
  15.  
  16.     x = speed * np.cos(angle) * time + initial_position[0]
  17.  
  18.     plt.plot(x,y, color = color)
  19.  
  20. GRAV_CONST = 10
  21.  
  22. #0 to 2, incrementing by 0.01
  23. time = np.arange(0, 2, 0.01)
  24.  
  25. blue = [0, 0, 1]
  26. red = [1, 0, 0]
  27. magenta = [1, 0, 1]
  28. green = [0, 1, 0]
  29. cyan = [0, 1, 1]
  30. yellow = [1, 1, 0]
  31. #list of lists
  32. colorList = [blue, red, magenta, green, cyan, yellow]
  33.  
  34. #incremental value for loop
  35. i = 0
  36. for x in range(15, 91, 15):
  37.     projectile_motion([0, 0], x, 10, time, colorList[i])
  38.    
  39.     i += 1
  40. plt.xlabel('x')
  41. plt.ylabel('y')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement