Inspiration
We were mesmerized by McGill's physics 2021 hackathon winners' project. The idea of simulating multiple masses and visualizing their interaction sounded fun. Hence, we took up the challenge and engineered a physics engine capable of simulating the gravitational interaction of multiple bodies.
What it does
The physics engine that we created is capable of simulating gravitational interactions through Newtonian physics between multiple massive bodies. We were able to model our planetary system within the physics engine and that is what we will be demoing!
How we built it
The physics engine was built in Python and used Newtonian physics to calculate the position and velocity of objects in relation to other objects in area. The physics engine streams the calculated values into Redis (in memory db). We used numpy to speed up the calculation of the force vectors by leveraging vector/matrix operations.
We have an API server created in Python using fast API that connects to the Redis server for engine updates.
Then we connect to a database (soupabase) to store the entities and send that to the front end that displays all of the objects. The frontend then displays the entities using a 3D library called 3JS.
Challenges we ran into
Time wasn't our best friend during the conception of the project. We took on a very ambitious project with many features that we weren't able to complete.
Accomplishments that we're proud of
However, we are extremely proud of getting the physics engine to work and seeing the interactions between the planets of our solar system. Although the visuals are lacking, the environment allowed us to alter the different planet parameters such as mass, velocity, position, etc. to give birth to an entirely new solar system that we could have been part of.
What we learned
We learned many things such as Redis, GRPC, FastAPI, Soupabase, and many other technology stacks that we have never used before. It was very challenging combining all of these together into one project. This was also the first time anyone has dealt with a 3D graphics engine library which was a challenge to get working correctly with the lighting, and position. We frequently came across issues regarding dependencies, compatibility between libraries, and many more.
We also learned a new mutation mechanism (polynomial mutation) frequently used in GA as well as other meta-heuristic algorithms that we considered using to calculate the optimal orbital trajectory.
Most importantly, we learned that with enough patience, we can solve any problem that we came across.
What's next for N-Body Simulation
We would like to take into account the speed of gravity, and general relativity while doing our numerical simulation. We also want to move the computation away from CPU to GPU using CuPy or other similar libraries for faster computation of force vectors. Moreover, we want to add some sort of criteria in our calculation such that we do not calculate the force between two objects if they are negligible. Moreover, we want to improve the numerical stability of our calculations by adding a small sigma value to our denominator if it's close to 0, and so on...
The next step for N-Body Simulation is adding body textures, improving upon the meta-heuristic algorithm that we use for calculating optimal orbital maneuvers and adding in a collision mechanism. We would like to ditch the point mass approach and simulate the actual size of the object as well as its density as well.
Built With
- fastapi
- grpc
- python
- react
- redis
- supabase
- three.js
- typescript
- vite

Log in or sign up for Devpost to join the conversation.