Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- #global because needs to be edited outside of function
- global GRAV_CONST
- def projectile_motion(initial_position, angle, speed, time, color):
- #because trigonometric functions only take in radians in python
- angle = np.radians(angle)
- GRAV_CONST = -9.8
- y = 0.5 * GRAV_CONST * (time ** 2) + speed * np.sin(angle) * time + initial_position[1]
- x = speed * np.cos(angle) * time + initial_position[0]
- plt.plot(x,y, color = color)
- GRAV_CONST = 10
- #0 to 2, incrementing by 0.01
- time = np.arange(0, 2, 0.01)
- blue = [0, 0, 1]
- red = [1, 0, 0]
- magenta = [1, 0, 1]
- green = [0, 1, 0]
- cyan = [0, 1, 1]
- yellow = [1, 1, 0]
- #list of lists
- colorList = [blue, red, magenta, green, cyan, yellow]
- #incremental value for loop
- i = 0
- for x in range(15, 91, 15):
- projectile_motion([0, 0], x, 10, time, colorList[i])
- i += 1
- plt.xlabel('x')
- plt.ylabel('y')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement