Skip to content

Commit a01c7e4

Browse files
authored
Gave meaningful names to function parameters
1 parent 4d4298c commit a01c7e4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

physics/relativistic_velocity_summation.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
of an object moving at speed v1 relative to a frame that is itself moving at velocity v
66
relative to an observer. I take the last one to be strictly lower than the speed of
77
light.
8-
The formula is v2 = (v1 + v)/(1 + v1 * v / c^2)
8+
The formula is v2 = (v1 + v)/(1 + v1 * v / c**2)
99
v1 - speed of the object relative to a moving frame
1010
v - speed of the moving frame
1111
c - speed of light in the vacuum
1212
v2 - speed of the object relative to an observer
1313
"""
1414

1515

16-
def relativistic_velocity_summation(v1: float, v: float) -> float:
16+
def relativistic_velocity_summation(
17+
object_velocity: float, frame_velocity: float
18+
) -> float:
1719
"""
1820
>>> relativistic_velocity_summation(200000000, 200000000)
1921
276805111.0636436
@@ -24,12 +26,15 @@ def relativistic_velocity_summation(v1: float, v: float) -> float:
2426
...
2527
ValueError: Speeds must not exceed light speed...
2628
"""
27-
if v1 > c or v >= c or v1 < -c or v <= -c:
29+
if (object_velocity > c or frame_velocity >= c or
30+
object_velocity < -c or frame_velocity <= -c):
2831
raise ValueError(
2932
"Speeds must not exceed light speed, and "
3033
"the frame speed must be lower than the light speed!"
3134
)
32-
return (v1 + v) / (1 + v1 * v / (c * c))
35+
numerator = object_velocity + frame_velocity
36+
denominator = 1 + object_velocity * frame_velocity / c**2
37+
return numerator / denominator
3338

3439

3540
if __name__ == "__main__":

0 commit comments

Comments
 (0)