-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_projectile.py
More file actions
47 lines (38 loc) · 1.16 KB
/
Copy pathbasic_projectile.py
File metadata and controls
47 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from math import *
import numpy as np
import matplotlib.pyplot as plt
def to_radians(angle_deg):
return angle_deg * (pi / 180)
def time_of_flight(v, angle):
g = 9.8
return (2 * v * sin(angle)) / g
def distance_travelled(v, angle):
g = 9.8
time = time_of_flight(v, angle)
return v * cos(angle) * time
def curve(x, angle, v):
g = 9.8
return x * np.tan(angle) - (g * (x**2)) / (2 * (v**2) * (np.cos(angle)**2))
def plot_trajectory(x, y):
plt.plot(x, y)
plt.title("Projectile Trajectory")
plt.xlabel("Distance (m)")
plt.ylabel("Height (m)")
plt.axhline(0, color='black')
plt.axvline(0, color='black')
plt.grid(True)
plt.show()
def main():
print("Hello")
v = float(input("Enter velocity in m/s: "))
angle_deg = float(input("Enter angle with ground in degrees: "))
angle = to_radians(angle_deg)
t = time_of_flight(v, angle)
d = distance_travelled(v, angle)
print("Time of flight:", t)
print("Distance travelled:", d, "\n")
x = np.linspace(0, d, 200)
y = curve(x, angle, v)
plot_trajectory(x, y)
if __name__ == "__main__":
main()