Calculate a Lorentz transformation for movement in the x direction given a velocity and a four-vector for an inertial reference frame If no four-vector is given, then calculate the transformation symbolically with variables >>> transform(29979245, np.array([1, 2, 3, 4])) ar
(velocity: float, event: np.ndarray | None = None)
| 135 | |
| 136 | |
| 137 | def transform(velocity: float, event: np.ndarray | None = None) -> np.ndarray: |
| 138 | """ |
| 139 | Calculate a Lorentz transformation for movement in the x direction given a |
| 140 | velocity and a four-vector for an inertial reference frame |
| 141 | |
| 142 | If no four-vector is given, then calculate the transformation symbolically |
| 143 | with variables |
| 144 | >>> transform(29979245, np.array([1, 2, 3, 4])) |
| 145 | array([ 3.01302757e+08, -3.01302729e+07, 3.00000000e+00, 4.00000000e+00]) |
| 146 | >>> transform(29979245) |
| 147 | array([1.00503781498831*ct - 0.100503778816875*x, |
| 148 | -0.100503778816875*ct + 1.00503781498831*x, 1.0*y, 1.0*z], |
| 149 | dtype=object) |
| 150 | >>> transform(19879210.2) |
| 151 | array([1.0022057787097*ct - 0.066456172618675*x, |
| 152 | -0.066456172618675*ct + 1.0022057787097*x, 1.0*y, 1.0*z], |
| 153 | dtype=object) |
| 154 | >>> transform(299792459, np.array([1, 1, 1, 1])) |
| 155 | Traceback (most recent call last): |
| 156 | ... |
| 157 | ValueError: Speed must not exceed light speed 299,792,458 [m/s]! |
| 158 | >>> transform(-1, np.array([1, 1, 1, 1])) |
| 159 | Traceback (most recent call last): |
| 160 | ... |
| 161 | ValueError: Speed must be greater than or equal to 1! |
| 162 | """ |
| 163 | # Ensure event is not empty |
| 164 | if event is None: |
| 165 | event = np.array([ct, x, y, z]) # Symbolic four vector |
| 166 | else: |
| 167 | event[0] *= c # x0 is ct (speed of light * time) |
| 168 | |
| 169 | return transformation_matrix(velocity) @ event |
| 170 | |
| 171 | |
| 172 | if __name__ == "__main__": |
no test coverage detected