|
| 1 | +""" |
| 2 | +Title : Calculate Light Aberration (astronomy) |
| 3 | +
|
| 4 | +Description : |
| 5 | + The below algorithm calculates astronomical light aberration as obtained |
| 6 | + using Special Relativity. |
| 7 | +
|
| 8 | +""" |
| 9 | + |
| 10 | +from math import atan, sqrt, tan |
| 11 | + |
| 12 | + |
| 13 | +def get_aberration_angle(angle_rest: float, velocity_over_c: float) -> float: |
| 14 | + """ |
| 15 | + This method calculates astronomical light aberration. |
| 16 | + The angle at rest 'angle_rest' is given in radians [rad] |
| 17 | + and is in the range (-pi, pi). |
| 18 | + The relative velocity of observer w.r.t. to the light emitting object is |
| 19 | + expressed by 'velocity_over_c' that is given as ratio for velocity |
| 20 | + w.r.t. the speed of light c and is in the range (0, 1). |
| 21 | +
|
| 22 | + https://en.wikipedia.org/wiki/Aberration_(astronomy) |
| 23 | +
|
| 24 | + tan(phi/2) = sqrt((1 - v/c)/(1 + v/c)) * tan(theta/2) |
| 25 | +
|
| 26 | + Where v is the relative velocity, phi is the observed angle with respect to the |
| 27 | + velocity vector (affected by light aberration), and theta is the angle observed |
| 28 | + angle in the limit of veclocity being equal to 0. |
| 29 | +
|
| 30 | + Examples: |
| 31 | + >>> get_aberration_angle(0.2, 0.1) |
| 32 | + 0.18102 |
| 33 | + >>> get_aberration_angle(0.2, 0) |
| 34 | + 0.2 |
| 35 | + >>> get_aberration_angle(0, 0.2) |
| 36 | + 0.0 |
| 37 | + >>> get_aberration_angle(-1.5707963267948966, 0.7) |
| 38 | + -0.7954 |
| 39 | + """ |
| 40 | + |
| 41 | + factor = sqrt((1 - velocity_over_c) / (1 + velocity_over_c)) |
| 42 | + angle_ab = 2 * atan(factor * tan(angle_rest / 2)) |
| 43 | + |
| 44 | + return round(angle_ab, 5) |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == "__main__": |
| 48 | + import doctest |
| 49 | + |
| 50 | + doctest.testmod() |
0 commit comments