This is the final project in the course DD1354 models and simulation KTH, the Royal Institute of Technology. This project models a Schwartzchild black hole and the geodesic orbits of photons in close proximity to it.
- Project directory: Implementation/black-hole-simulation-cpp
- Project specification: report/build/project_specification.pdf
- Project report: report/build/report.pdf
- Project blog: blog
By going to this repository's pages site at https://mrgreenscout.github.io/Black-hole-physics-sim/ you can test the program out.
I reserve myself for bugs in the web build, I have tested it on Ubuntu Linux with firefox and it works well, but on windows (opera) for spawning photons the drag-clicking needs another click for it to actually spawn, it is what it is.
- Start off by cloning the repository
- cd into
Implementations/black-hole-simulation-cpp - Run the command
bash run.shin the terminal - The program window should open
- bash is installed
- SDL2 is installed
- g++ is installed
This has been built on Ubuntu Linux, I believe it should work quite flawlessly on MacOS but some difficulties may arise on Windows.
This is probably the final blog post for this project. I am done writing my report and the last change I made to the program was adding a test for evaluating the accuracy of the project. This can be tested by uncommenting #define EVALUATING in /src/main.cpp. Though a rather limited evaluation, since it only tests a specific part of the simulation, the results should suggest a program that is rather accurate. The results of the test may be found in the report
P.s. I have still not updated the web build. I will probably fix that but I can't promise anything.
Updated the visualization, now the coordinate system correctly converts from screen space to world space to screen space again, so now I added a circle for the photon sphere too, the distance from the black hole a photon can achieve a stable orbit. Inside the photon sphere the photon collapses into the black hole and outside the photon escapes the black holes grasp.
Disclaimer: I have not yet updated the web build, will be updated later
I got github pages support working, now you can access the program from anywhere as simple as going to this link.
Finally got it working, such a stupid bug, don't accidentally forget that the path of the photons should be renderer using cartesian coordinates not polar...
Here are some pictures of a working photon simulation:
Loads of bugs still remain, hopefully I will be able to quickly squash them.
The biggest are:
- Black hole repels photos
- Interfacing with the program is hindered by faulty coordinate system conversion between screen and world space
Getting a window open and drawing a circle was quite easy with SDL2. After that I implemented panning around with the mouse, and getting the circle to represent a black hole, where the circles radius depends on the black hole's mass.
The photons themselves were more difficult, sometimes just converting between coordinate systems and other times fundamental failures in physics. Below you can see some of the first (and the most buggy) photons in the program, as you can see the photon to the right has done a U-turn before the black hole, very realistic...
My first plan was creating this project in Unity, but after further thought and some programmatic testing I changed direction. Since time is limited, and I'm not that proficient in Unity I have decided to change the program to be built with C++ and SDL2, since I am more comfortable with that.
I have since started work on the 2D version of the project and I am almost done with the null geodesic logic for the photon. Finding the turning point of a photon's path (determining the sign of
Since the last post I have basically only been trying to understand the subject, surprisingly (or maybe not so surprising) general relativity is quite difficult to wrap your mind about.
To understand the math I have found some really good resources, the wikipedia page about the Schwartzchild metric had a really good outline how to model a photon orbiting a black hole using Runge-Kutta 4 for example.
With the use of wikipedia, a couple of lectures found online, and a couple of papers I was able to derive a form of the Schwartzchild solution of the geodesics equations useful for simulation using RK4.
Finding the math itself was actually the easier part, understanding it was way more difficult. In some cases (particularly understanding the impact parameter
This is the final project for the course DD1354 Models and Simulation. This project will model a black hole and how it bends space time altering the path of photons.





