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

Function horizontal_distance

physics/horizontal_projectile_motion.py:48–75  ·  view source on GitHub ↗

r""" Returns the horizontal distance that the object cover Formula: .. math:: \frac{v_0^2 \cdot \sin(2 \alpha)}{g} v_0 - \text{initial velocity} \alpha - \text{angle} >>> horizontal_distance(30, 45) 91.77 >>> horizontal_distance(100

(init_velocity: float, angle: float)

Source from the content-addressed store, hash-verified

46
47
48def horizontal_distance(init_velocity: float, angle: float) -> float:
49 r"""
50 Returns the horizontal distance that the object cover
51
52 Formula:
53 .. math::
54 \frac{v_0^2 \cdot \sin(2 \alpha)}{g}
55
56 v_0 - \text{initial velocity}
57
58 \alpha - \text{angle}
59
60 >>> horizontal_distance(30, 45)
61 91.77
62 >>> horizontal_distance(100, 78)
63 414.76
64 >>> horizontal_distance(-1, 20)
65 Traceback (most recent call last):
66 ...
67 ValueError: Invalid velocity. Should be a positive number.
68 >>> horizontal_distance(30, -20)
69 Traceback (most recent call last):
70 ...
71 ValueError: Invalid angle. Range is 1-90 degrees.
72 """
73 check_args(init_velocity, angle)
74 radians = deg_to_rad(2 * angle)
75 return round(init_velocity**2 * sin(radians) / g, 2)
76
77
78def max_height(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