fasttrajectory
@njit
def
simulate_projectile( velocity: float, angle_deg: float, dt: float = 0.01, drag: float = 0.0, gravity: float = 9.81):
10@njit 11def simulate_projectile( 12 velocity: float, 13 angle_deg: float, 14 dt: float = 0.01, 15 drag: float = 0.0, 16 gravity: float = 9.81, 17): 18 """ 19 Simulate projectile motion with optional air drag. 20 21 Parameters 22 ---------- 23 velocity : float 24 Initial velocity in m/s. 25 angle_deg : float 26 Launch angle in degrees. 27 dt : float 28 Time step in seconds. 29 drag : float 30 Air resistance coefficient. 31 gravity : float 32 Gravitational acceleration in m/s^2. 33 34 Returns 35 ------- 36 tuple[np.ndarray, np.ndarray] 37 Arrays of x and y coordinates. 38 """ 39 40 angle_rad = np.radians(angle_deg) 41 42 vx = velocity * np.cos(angle_rad) 43 vy = velocity * np.sin(angle_rad) 44 45 x = 0.0 46 y = 0.0 47 48 xs = [x] 49 ys = [y] 50 51 while y >= 0: 52 53 speed = np.sqrt(vx**2 + vy**2) 54 55 ax = -drag * speed * vx 56 ay = -gravity - drag * speed * vy 57 58 vx += ax * dt 59 vy += ay * dt 60 61 x += vx * dt 62 y += vy * dt 63 64 xs.append(x) 65 ys.append(y) 66 67 return np.array(xs), np.array(ys)
Simulate projectile motion with optional air drag.
Parameters
velocity : float Initial velocity in m/s. angle_deg : float Launch angle in degrees. dt : float Time step in seconds. drag : float Air resistance coefficient. gravity : float Gravitational acceleration in m/s^2.
Returns
tuple[np.ndarray, np.ndarray] Arrays of x and y coordinates.
def
flight_time(velocity: float, angle_deg: float, gravity: float = 9.81) -> float:
71def flight_time( 72 velocity: float, 73 angle_deg: float, 74 gravity: float = 9.81, 75) -> float: 76 """ 77 Compute total projectile flight time without air resistance. 78 79 Parameters 80 ---------- 81 velocity : float 82 Initial velocity in m/s. 83 84 angle_deg : float 85 Launch angle in degrees. 86 87 gravity : float 88 Gravitational acceleration in m/s^2. 89 90 Returns 91 ------- 92 float 93 Total flight time in seconds. 94 """ 95 angle_rad = np.radians(angle_deg) 96 97 return 2 * velocity * np.sin(angle_rad) / gravity
Compute total projectile flight time without air resistance.
Parameters
velocity : float Initial velocity in m/s.
angle_deg : float Launch angle in degrees.
gravity : float Gravitational acceleration in m/s^2.
Returns
float Total flight time in seconds.