Projectile motion shows up everywhere: a thrown ball, a water jet, a football kick, even a character jumping in a game. The physics behind it is simple, and a few lines of Python can do all the maths for you.
The idea in one minute
When you launch an object with speed v0 at an angle θ, gravity pulls it down while its horizontal speed stays constant. That gives three useful formulas:
-
Time of flight:
T = 2 * v0 * sin(θ) / g -
Maximum height:
H = (v0 * sin(θ))² / (2 * g) -
Range:
R = v0² * sin(2θ) / g
Here g is about 9.81 m/s² on Earth.
Python script
import math
def projectile(v0, angle_deg, g=9.81):
theta = math.radians(angle_deg)
time_of_flight = 2 * v0 * math.sin(theta) / g
max_height = (v0 * math.sin(theta)) ** 2 / (2 * g)
horizontal_range = v0 ** 2 * math.sin(2 * theta) / g
return time_of_flight, max_height, horizontal_range
t, h, r = projectile(20, 45)
print(f"Flight time: {t:.2f} s")
print(f"Max height: {h:.2f} m")
print(f"Range: {r:.2f} m")
For a launch speed of 20 m/s at 45°, you should get about 2.88 s of flight time, 10.19 m of maximum height and 40.77 m of range.
Try it yourself
- Change the angle to 30° and 60°. You will notice both give the same range.
- Find the angle that gives the longest range. Without air resistance, it is 45°.
- Add air resistance to make the model more realistic.
Check your answers
If you want to compare your results, the free projectile motion calculator shows the formula, the substitution and the final answer step by step.
For the theory behind it, including why the path is a parabola and why 45° is best, there is a full projectile motion guide with worked examples.
I also help run Physics Fundamentals, a free site with physics articles, calculators and games, so full disclosure on that.
Happy coding! If you would like a follow-up on circular motion or energy conservation in Python, let me know in the comments.
Top comments (0)