Skip to content

MrGreenScout/Black-hole-physics-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Black-hole-Physics-Sim

Bending space time 1

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.

Important links

How to run

Web build

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.

Compiling from source

  1. Start off by cloning the repository
  2. cd into Implementations/black-hole-simulation-cpp
  3. Run the command bash run.sh in the terminal
  4. The program window should open

Prerequisites

  • bash is installed
  • SDL2 is installed
  • g++ is installed

Note

This has been built on Ubuntu Linux, I believe it should work quite flawlessly on MacOS but some difficulties may arise on Windows.

Blog

2026-03-31: Post 9 - Created a evaluation environment and Finalized report

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.

2026-03-19: Post 8 - Updated visualization and another coordinate system bug

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.

Updated image

Disclaimer: I have not yet updated the web build, will be updated later

2026-03-13: Post 7 - Now you can try it out on the web!

I got github pages support working, now you can access the program from anywhere as simple as going to this link.

2026-03-13: Post 6 - Date of submission: Part 2

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:

Bending space time 1

Bending space time 2

2026-03-13: Post 5 - Date of submission: Part 1

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

2026-03-12: Post 4 - First window and first photon

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.

First window

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...

First buggy photon

2026-03-10: Post 3 - A rethinking of project

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 $\frac{dr}{ds}$) has proven more difficult than expected but I will prevail...

2026-03-05: Post 2 - Background research

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 $b$) I made use of generative AI, where through a sort of socratic learning I was greatly helped.

2026-02-24: Post 1 - Hello, Space!

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.

Project specification

About

A physical simulation of a Schwartzchild black hole and the geodesic paths of photons close to it. This repository contains the final project in the course DD1354 models and simulation at KTH, the Royal Institute of Technology.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors