Ad

Given a projectile speed s in m/s, the angle of the initial velocity beta in degrees, and the height of the origin y, calculate the time until the projectile arrives at the ground (y=0).

Further note:

  • Assume there is no drag.
  • 0 <= s, y <= 1000, 0 <= beta <= 90,
  • The time has to be accurate to three decimals.
  • Use 9.81 m/s^2 as the gravitional acceleration.
import math

def calc_time_of_impact(speed, angle, origin_y):

    x_value = 0
    y_value = 0
    time = 0.0001

    def x_formula(t): return speed * t * \
        math.cos(angle * math.pi / 180)

    def y_formula(t): return speed * t * \
        math.sin(angle * math.pi / 180) - 9.81/2*t*t

    while y_value >= -origin_y:
        x_value = x_formula(time)
        y_value = y_formula(time)
        time += 0.0001

    return time