Skip to content
scipython.com

P2.7.5Range and height of a projectile

The range of a projectile launched at an angle \(\alpha\) and speed \(v\) on flat terrain is:

\[R = \frac{v^2\sin2\alpha}{g},\]

where \(g\) is the acceleration due to gravity which may be taken to be \(9.81\;\mathrm{m\,s^{-2}}\) for Earth. The maximum height attained by the projectile is given by:

\[H = \frac{v^2\sin^2\alpha}{2g}.\]

(We neglect air resistance and the curvature and rotation of the Earth.) Write a function to calculate and return the range and maximum height of a projectile, taking \(\alpha\) and \(v\) as arguments. Test it with the values \(v = 10\;\mathrm{m\,s^{-1}}\) and \(\alpha = 30^\circ\).

Show solution

Here is one approach.

import math
g = 9.81

def calc_range_height(v, alpha):
    """
    Return the range and height of a projectile.

    Return the range, R, and height, H, of a projectile launched with
    velocity v at angle alpha to a stationary, horizontal surface.
    Air-resistance is neglected.

    """

    R = v**2 * math.sin(2.*alpha) / g
    H = v**2 * math.sin(alpha)**2 / 2 / g
    return R, H

# speed in m/s, elevation angle in radians (convert from degrees)
v, alpha = 10., math.radians(30.)
R, H = calc_range_height(v, alpha)
print('Range is {:.2f} m; Max height is {:.2f} m'.format(R,H))

For the test case suggested the output is:

Range is 8.83 m; Max height is 1.27 m