-
-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Relativistic velocity summation function #14357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
6b973f9
291588c
e6f7074
aded8bb
ed9b0fd
4d4298c
a01c7e4
5b573f9
545f810
7d77c88
eb2b060
3d7a039
4508c01
487dd7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| c = 299792458 | ||
|
|
||
| """ | ||
| The relativistic velocity summation formula calculates the combined velocity v2 | ||
| of an object moving at speed v1 relative to a frame that is itself moving at velocity v | ||
| relative to an observer. I take the last one to be strictly lower than the speed of | ||
| light. | ||
| The formula is v2 = (v1 + v)/(1 + v1 * v / c^2) | ||
| """ | ||
|
|
||
|
|
||
| def relativistic_velocity_summation(v1: float, v: float) -> float: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide descriptive name for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide descriptive name for the parameter: |
||
| """ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide descriptive name for the parameter: |
||
| >>> relativistic_velocity_summation(200000000, 200000000) | ||
| 276805111.0636436 | ||
| >>> relativistic_velocity_summation(299792458, 100000000) | ||
| 299792458.0 | ||
| >>> relativistic_velocity_summation(100000000, 299792458) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Speeds must not exceed light speed... | ||
| """ | ||
| if v1 > c or v >= c or v1 < -c or v <= -c: | ||
| raise ValueError( | ||
| "Speeds must not exceed light speed, and " | ||
| "the frame speed must be lower than the light speed!" | ||
| ) | ||
| return (v1 + v) / (1 + v1 * v / (c * c)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from doctest import testmod | ||
|
|
||
| testmod() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error occurred while parsing the file:
physics/relativistic_velocity_summation.py