Python simulation visualizing the behavior of light rays around a black hole in 2D space using the Schwarzschild metric. The user can observe gravitational lensing effects in response to a strong gravitational field.
- Simulates light ray trajectories in Schwarzschild geometry
- Visualizes multiple light rays with different initial positions
- Animated visualization showing the progressive movement of light rays
- Uses proper relativistic calculations for null geodesics
- Includes numerical stability improvements for accurate simulation
- Python 3.x
- Pip for Python 3
- NumPy
- Matplotlib
- SciPy
You can use winget to easily install python and pip.
winget install Python.Python.3Python backend tkinter may need to be installed on some systems.
sudo apt install python3-tk python3-pipsudo dnf install python3-tkinter python3-pipIf using system-wide python, make sure to use pip3 to install packages and python3 to create the virtual environment or run the script.
The Schwarzschild metric describes the geometry of spacetime around a non-rotating, chargeless, and spherically symmetric mass:
where
Light rays follow null geodesics, which are paths where the spacetime interval is zero (
where
The motion of light rays can be understood through an effective potential:
The closest approach of a light ray to the black hole is determined by the impact parameter
The photon sphere occurs at
git clone https://github.com/ZZBaron/2D-Black-Hole-Sim.git
cd 2D-Black-Hole-Sim# Replace `env` with your desired environment name
python -m venv env
env\Scripts\activatepython3 -m venv env
source env/bin/activatepip install -r requirements.txtRun the simulation by executing:
python "2D Black Hole Light Sim.py"MIT License