Time of flight computed deterministically from input values.
import math import numpy as np g = 9.81 def calc_time_of_impact(speed, angle, origin_y): angle = np.deg2rad(angle) if origin_y: return (speed * math.sin(angle) + math.sqrt((speed * math.sin(angle))**2 + 2 * g * origin_y)) / g return 2 * speed * math.sin(angle) / g
- import math
- import numpy as np
- g = 9.81
- def calc_time_of_impact(speed, angle, origin_y):
x_value = 0y_value = 0time = 0.0001def 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*twhile y_value >= -origin_y:x_value = x_formula(time)y_value = y_formula(time)time += 0.0001return time- angle = np.deg2rad(angle)
- if origin_y:
- return (speed * math.sin(angle) + math.sqrt((speed * math.sin(angle))**2 + 2 * g * origin_y)) / g
- return 2 * speed * math.sin(angle) / g