This Python script simulates the motion of a projectile considering air resistance. It calculates and displays the horizontal distance traveled by the projectile before it hits the ground. The simulation accounts for gravity, air resistance, and user-defined initial conditions.
g: Acceleration due to gravity (m/s^2).k: Air resistance constant (kg/s). Represents the drag on the projectile.m: Mass of the projectile (kg).
x0, y0: Initial position (m) of the projectile (default: (0.0, 0.0)).v0: Initial velocity (m/s) of the projectile.theta: Launch angle in radians.
- Calculates initial horizontal (
v0x) and vertical (v0y) velocities. - Defines time values for simulation from
0tot_maxseconds with a time step ofdt.
horizontal_motion(vx, t): Computes the horizontal velocity of the projectile at timet.vertical_motion(vy, t): Computes the vertical velocity of the projectile at timet.
- Utilizes functional programming to update velocities over time.
- Finds the index when the projectile hits the ground (y = 0).
- Calculates the horizontal distance traveled when the projectile hits the ground.
- Prints the horizontal distance traveled by the projectile.
To use this script, modify the initial conditions (e.g., v0, theta) as needed and run the script. The horizontal distance traveled will be displayed as output.
# Example: Modify initial conditions
v0 = 100.0 # Initial velocity (m/s)
theta = np.radians(45) # Launch angle in radians
# Run the simulation
# ...
# Output will show the horizontal distance traveledOutput
