The Lorentz Transform Visualized with Python
T he Lorentz transformation is the backbone of special relativity and encapsulates all its bizarre and intriguing effects like time dilation, length contraction, and breakdown of simultaneity. Although easy to state mathematically, it can be hard to get a mental, pictorial, and intuitive representation. This is what we will do today. We will create a dynamic, interactive visualization of the Lorentz transformation using Python. But before we delve into the code, let’s see what the Lorentz transformation looks like and what are its more important properties.
The Lorentz transformation and its properties
The Lorentz transformation is a fundamental concept in the theory of special relativity that describes how the coordinates of events in one reference frame are related to those in another reference frame that is moving at a constant velocity with respect to the first one. It is a mathematical transformation that preserves the speed of light as a universal constant and reconciles the apparent inconsistencies that arise when the laws of physics are formulated in different reference frames.
The Lorentz transformation can be expressed in terms of the four-dimensional space-time coordinates (ct,x,y,z) of an event, where c is the speed of light, t is the time coordinate, and x, y, and z are the spatial coordinates. Let us consider two inertial reference frames, denoted by S and S′, which are moving relative to each other with a relative velocity v along the x-axis. We assume that both frames have their origins at the same point at time t=t′=0. The coordinates of an event that occurs at (ct,x,y,z) in S are related to those in S′ by the Lorentz transformation:
where β=v/c, and γ=1/√1−β² is the Lorentz factor, and we have assumed that the y and z coordinates are the same in both frames. The Lorentz transformation can also be expressed in matrix form:
The Lorentz transformation has several important properties that reflect the fundamental principles of special relativity. It is a non-trivial transformation that depends on the relative velocity between the frames, and reduces to the identity transformation when the frames coincide.
One of the most remarkable consequences of the Lorentz transformation is the so-called time dilation effect. According to the transformation, the time coordinate of an event in S′ is given by a combination of the time coordinate and the spatial coordinate in S. This implies that clocks that are moving relative to an observer in S appear to run slower than those at rest with respect to the observer. This effect has been confirmed experimentally in numerous experiments, including the famous Hafele-Keating experiment, which used atomic clocks to measure the time dilation caused by the motion of an airplane.
Another consequence of the Lorentz transformation is the length contraction effect. According to the transformation, the spatial coordinates of an event in S′ are given by a combination of the spatial coordinates and the time coordinate in S. This implies that objects that are moving relative to an observer in S appear to be shorter along the direction of motion than their rest length. This effect has also been confirmed experimentally in various ways, such as by measuring the length of fast-moving particles using particle accelerators.
The Lorentz transformation also implies the relativity of simultaneity, which means that events that are simultaneous in one frame are not necessarily simultaneous in another frame that is moving relative to the first one. This effect arises because the time coordinate is no longer absolute but depends on the frame of reference.
How to do differentiation with the Fourier Transform…
Another striking feature of the Lorentz transformation is the presence of a hyperbola known as the invariant hyperbola. The invariant hyperbola is defined as the locus of points that satisfy the equation:
where τ is the proper time, which is the time measured by an observer moving together with the reference frame. For simplicity, we have dropped the y- and z-coordinates, such that we can really speak of a hyperbola. Otherwise, it would be its higher-dimensional counterpart.
The invariant hyperbola plays an important role in special relativity because it is invariant under Lorentz transformations. This means that if an event satisfies the equation of the invariant hyperbola in one reference frame, it will also satisfy the equation in any other reference frame that is moving at a constant velocity relative to the first one. This implies that the invariant hyperbola is a fundamental geometric object that describes the relationship between the coordinates of events in different reference frames.
Plot the light cones
Now let's start to visualize the Lorentz transformation to get a better understanding of what is going on. First, we will plot the light cones. These are the points in the spacetime diagram that can be reached by light rays starting or arriving at the location x=0 at time t=0.
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 6));
ax.set_aspect('equal')
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_xlabel('x')
ax.set_ylabel('t')
N = 201
t = np.linspace(-100, 100, N)
# Plot the light cones
ax.plot(t, t, color='green', linestyle='--')
ax.plot(t, -t, color='green', linestyle='--')
ax.fill_between(t, t, -t, color='gray', alpha=0.7)
ax.fill_between(t, -t, t, color='gray', alpha=0.7)
The light cone itself is formed by the green dashed lines. The white areas are the location of all so-called time-like events, i.e. events that are in causal connection with the origin, i.e. they could exchange signals with the observer at the origin at t=0. The shaded regions are outside of the light cone and are all so-called space-like events. All points in the shaded region are in no causal connection with the observer at t=0 because this would require a signal traveling faster than light.
Add the invariant hyperbolas
Next, we will add the invariant unit hyperbolas:
t_fine = np.linspace(-5, 5, 100)
xh1 = np.cosh(t_fine)
yh1 = np.sinh(t_fine)
xh2 = -np.cosh(t_fine)
yh2 = np.sinh(t_fine)
ax.plot(xh1, yh1, color='blue')
ax.plot(xh2, yh2, color='blue')
ax.plot(yh1, xh1, color='blue')
ax.plot(yh2, xh2, color='blue')
display(fig)
Add coordinate grids
Then, we add the coordinate grid for the unprimed coordinates, i.e. lines of constant t and constant x.
N = 201
t = np.linspace(-100, 100, N)
x = np.linspace(-100, 100, N)
T, X = np.meshgrid(t, x)
...
ax.plot(T, X, '-', color='lightgray')
ax.plot(X, T, '-', color='lightgray')
and finally we add the coordinate grid after the Lorentz transformation:
def lorentz_transform(beta):
gamma = 1 / np.sqrt(1 - beta**2)
return np.array([[gamma, gamma*beta], [gamma*beta, gamma]])
beta = 0.3
# Calculate the transformed coordinate grid:
TX = np.array([T.reshape(-1), X.reshape(-1)])
TX_transformed = lorentz_transform(beta).dot(TX)
T_transformed = TX_transformed[0].reshape(T.shape)
X_transformed = TX_transformed[1].reshape(X.shape)
# Plot the transformed grid
ax.plot(T_transformed, X_transformed, '-', color='black')
ax.plot(X_transformed, T_transformed, '-', color='black')
The Lorentz transformation tilts the original coordinate axes. Also note that points that are on the invariant hyperbola stay on the hyperbola. For instance, the point at (t,x)=(0,1) moves to (t′,x′)=(0,1) which is still on the hyperbola, as you can see from the figure.
Adding interactivity
That plot is already quite nice, but it would be nicer to have interactive behavior. So we move the plotting code and add a slider for the velocity β. When we click the slider, the plot function is triggered and the plot gets updated. Here is the final and complete code:
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, FloatSlider
def lorentz_transform(beta):
gamma = 1 / np.sqrt(1 - beta**2)
return np.array([[gamma, gamma*beta], [gamma*beta, gamma]])
def make_plot(beta):
fig, ax = plt.subplots(figsize=(6, 6));
ax.set_aspect('equal')
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_xlabel('x')
ax.set_ylabel('t')
# Define the coarse grid:
N = 201
t = np.linspace(-100, 100, N)
x = np.linspace(-100, 100, N)
T, X = np.meshgrid(t, x)
# Plot the light cones
ax.plot(t, t, color='green', linestyle='--')
ax.plot(t, -t, color='green', linestyle='--')
ax.fill_between(t, t, -t, color='gray', alpha=0.7)
ax.fill_between(t, -t, t, color='gray', alpha=0.7)
# Calculate the transformed coordinate grid:
TX = np.array([T.reshape(-1), X.reshape(-1)])
TX_transformed = lorentz_transform(beta).dot(TX)
T_transformed = TX_transformed[0].reshape(T.shape)
X_transformed = TX_transformed[1].reshape(X.shape)
# Plot the original grid
ax.plot(T, X, '-', color='lightgray')
ax.plot(X, T, '-', color='lightgray')
# Plot the invariant hyperbola
t_fine = np.linspace(-5, 5, 100)
xh1 = np.cosh(t_fine)
yh1 = np.sinh(t_fine)
xh2 = -np.cosh(t_fine)
yh2 = np.sinh(t_fine)
ax.plot(xh1, yh1, color='blue')
ax.plot(xh2, yh2, color='blue')
ax.plot(yh1, xh1, color='blue')
ax.plot(yh2, xh2, color='blue')
# Plot the transformed grid
ax.plot(T_transformed, X_transformed, '-', color='black')
ax.plot(X_transformed, T_transformed, '-', color='black')
ax.set_title(f'$\\beta$ = {beta}')
plt.show()
interact(make_plot, beta=FloatSlider(min=0, max=0.99999, step=0.02, value=0.));
Conclusion
In conclusion, we have seen how to create an interactive visualization of the Lorentz transformation using Python, which helps to provide a more intuitive understanding of the concept. The Lorentz transformation is a fundamental principle in special relativity that reconciles the apparent inconsistencies that arise when the laws of physics are formulated in different reference frames. It preserves the speed of light as a universal constant and has several important properties, including linearity, symmetry, and dependence on relative velocity between the frames. The Lorentz transformation also leads to some of the most fascinating consequences of special relativity, such as time dilation, length contraction, and the breakdown of simultaneity. By visualizing the transformation step-by-step, we can better understand these concepts and gain a deeper appreciation for the elegance and beauty of special relativity.