MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / max_height

Function max_height

physics/horizontal_projectile_motion.py:78–105  ·  view source on GitHub ↗

r""" Returns the maximum height that the object reach Formula: .. math:: \frac{v_0^2 \cdot \sin^2 (\alpha)}{2 g} v_0 - \text{initial velocity} \alpha - \text{angle} >>> max_height(30, 45) 22.94 >>> max_height(100, 78) 487.82

(init_velocity: float, angle: float)

Source from the content-addressed store, hash-verified

76
77
78def max_height(init_velocity: float, angle: float) -> float:
79 r"""
80 Returns the maximum height that the object reach
81
82 Formula:
83 .. math::
84 \frac{v_0^2 \cdot \sin^2 (\alpha)}{2 g}
85
86 v_0 - \text{initial velocity}
87
88 \alpha - \text{angle}
89
90 >>> max_height(30, 45)
91 22.94
92 >>> max_height(100, 78)
93 487.82
94 >>> max_height("a", 20)
95 Traceback (most recent call last):
96 ...
97 TypeError: Invalid velocity. Should be an integer or float.
98 >>> horizontal_distance(30, "b")
99 Traceback (most recent call last):
100 ...
101 TypeError: Invalid angle. Should be an integer or float.
102 """
103 check_args(init_velocity, angle)
104 radians = deg_to_rad(angle)
105 return round(init_velocity**2 * sin(radians) ** 2 / (2 * g), 2)
106
107
108def total_time(init_velocity: float, angle: float) -> float:

Callers 2

test_motionFunction · 0.85

Calls 2

sinFunction · 0.90
check_argsFunction · 0.85

Tested by 1

test_motionFunction · 0.68