|
10 | 10 | */ |
11 | 11 | public final class Relativity { |
12 | 12 |
|
13 | | - /* Speed of light in m s^-1 */ |
14 | | - public static final double SPEED_OF_LIGHT = 299792458.0; |
| 13 | + /* Speed of light in m s^-1 */ |
| 14 | + public static final double SPEED_OF_LIGHT = 299792458.0; |
15 | 15 |
|
16 | | - /** |
| 16 | + /** |
17 | 17 | * Private constructor to prevent instantiation of this utility class. |
18 | 18 | */ |
19 | | - private Relativity() { |
20 | | - } |
| 19 | + private Relativity() { |
| 20 | + } |
21 | 21 |
|
22 | | - /** |
23 | | - * Calculates the gamma parameter that is of paramount importance in relativity |
24 | | - * theory. It is a dimensionless parameter that is equal to 1 for zero velocity |
25 | | - * but tends to infinity when velocity approaches the speed of light. |
26 | | - * |
27 | | - * @param v The velocity (m/s). |
28 | | - * @return The value of gamma parameter. |
29 | | - */ |
30 | | - public static double gamma(double v) { |
31 | | - if (Math.abs(v) >= SPEED_OF_LIGHT) { |
32 | | - throw new IllegalArgumentException("Speed must be lower than the speed of light"); |
33 | | - } |
34 | | - return 1.0 / Math.sqrt(1 - v * v / (SPEED_OF_LIGHT * SPEED_OF_LIGHT)); |
35 | | - } |
| 22 | + /** |
| 23 | + * Calculates the gamma parameter that is of paramount importance in relativity |
| 24 | + * theory. It is a dimensionless parameter that is equal to 1 for zero velocity |
| 25 | + * but tends to infinity when velocity approaches the speed of light. |
| 26 | + * |
| 27 | + * @param v The velocity (m/s). |
| 28 | + * @return The value of gamma parameter. |
| 29 | + */ |
| 30 | + public static double gamma(double v) { |
| 31 | + if (Math.abs(v) >= SPEED_OF_LIGHT) { |
| 32 | + throw new IllegalArgumentException("Speed must be lower than the speed of light"); |
| 33 | + } |
| 34 | + return 1.0 / Math.sqrt(1 - v * v / (SPEED_OF_LIGHT * SPEED_OF_LIGHT)); |
| 35 | + } |
36 | 36 |
|
37 | | - /** |
38 | | - * Calculates the length of an object in the moving frame. |
39 | | - * |
40 | | - * @param length The length of an object in its own frame (m). |
41 | | - * @param v The velocity of the object (m/s). |
42 | | - * @return The length of an object in the laboratory frame (m). |
43 | | - */ |
44 | | - public static double lengthContraction(double length, double v) { |
45 | | - if (length < 0) { |
46 | | - throw new IllegalArgumentException("Length must be non-negative"); |
47 | | - } |
48 | | - return length / gamma(v); |
49 | | - } |
| 37 | + /** |
| 38 | + * Calculates the length of an object in the moving frame. |
| 39 | + * |
| 40 | + * @param length The length of an object in its own frame (m). |
| 41 | + * @param v The velocity of the object (m/s). |
| 42 | + * @return The length of an object in the laboratory frame (m). |
| 43 | + */ |
| 44 | + public static double lengthContraction(double length, double v) { |
| 45 | + if (length < 0) { |
| 46 | + throw new IllegalArgumentException("Length must be non-negative"); |
| 47 | + } |
| 48 | + return length / gamma(v); |
| 49 | + } |
50 | 50 |
|
51 | | - /** |
52 | | - * Calculates the time that has passed in the moving frame. |
53 | | - * |
54 | | - * @param length The time that has passed in the object's own frame (s). |
55 | | - * @param v The velocity of the object (m/s). |
56 | | - * @return The time that has passed in the laboratory frame (s). |
57 | | - */ |
58 | | - public static double timeDilation(double time, double v) { |
59 | | - if (time < 0) { |
60 | | - throw new IllegalArgumentException("Time must be non-negative"); |
61 | | - } |
62 | | - return time * gamma(v); |
63 | | - } |
| 51 | + /** |
| 52 | + * Calculates the time that has passed in the moving frame. |
| 53 | + * |
| 54 | + * @param length The time that has passed in the object's own frame (s). |
| 55 | + * @param v The velocity of the object (m/s). |
| 56 | + * @return The time that has passed in the laboratory frame (s). |
| 57 | + */ |
| 58 | + public static double timeDilation(double time, double v) { |
| 59 | + if (time < 0) { |
| 60 | + throw new IllegalArgumentException("Time must be non-negative"); |
| 61 | + } |
| 62 | + return time * gamma(v); |
| 63 | + } |
64 | 64 |
|
65 | | - /** |
66 | | - * Calculates the velocity with respect to the moving frame. |
67 | | - * |
68 | | - * @param v1 The velocity of the object with respect to laboratory frame (m/s). |
69 | | - * @param v The velocity of the moving frame (m/s). |
70 | | - * @return The velocity with respect to the moving frame (m/s). |
71 | | - */ |
72 | | - public static double velocityAddition(double v1, double v) { |
73 | | - if (Math.abs(v1) > SPEED_OF_LIGHT) { |
74 | | - throw new IllegalArgumentException("Speed must not exceed the speed of light"); |
75 | | - } |
76 | | - if (Math.abs(v) >= SPEED_OF_LIGHT) { |
77 | | - throw new IllegalArgumentException("Frame speed must be lower than the speed of light"); |
78 | | - } |
79 | | - return (v1 - v) / (1 - v1 * v / (SPEED_OF_LIGHT * SPEED_OF_LIGHT)); |
80 | | - } |
| 65 | + /** |
| 66 | + * Calculates the velocity with respect to the moving frame. |
| 67 | + * |
| 68 | + * @param v1 The velocity of the object with respect to laboratory frame (m/s). |
| 69 | + * @param v The velocity of the moving frame (m/s). |
| 70 | + * @return The velocity with respect to the moving frame (m/s). |
| 71 | + */ |
| 72 | + public static double velocityAddition(double v1, double v) { |
| 73 | + if (Math.abs(v1) > SPEED_OF_LIGHT) { |
| 74 | + throw new IllegalArgumentException("Speed must not exceed the speed of light"); |
| 75 | + } |
| 76 | + if (Math.abs(v) >= SPEED_OF_LIGHT) { |
| 77 | + throw new IllegalArgumentException("Frame speed must be lower than the speed of light"); |
| 78 | + } |
| 79 | + return (v1 - v) / (1 - v1 * v / (SPEED_OF_LIGHT * SPEED_OF_LIGHT)); |
| 80 | + } |
81 | 81 | } |
0 commit comments