- Thousands of particles simulated.
- Gravitational forces calculated between every possible pair of particles, every frame. (Multithreaded O(n2)).
- Collision detection combines particles whenever they touch. (Circle collision.)
- Technologies: C++20, OpenGL. CUDA coming soon.
$ git clone --recurse-submodules https://github.com/corecursion/gravity-simulation.git
$ cd gravity-simulation
$ mkdir build
$ cmake -B build
$ cmake --build build
$ build/gravity-simulationParticles in this simulation instantly combine whenever they touch, which isn't like the real world where things can bounce, bend, spin, and pieces can break off, but it should be good enough for experimenting with large-scale gravitational forces.
Basic testing of Newton's Law of Universal Gravitation with idealized particles simulated using C++20:
The yellow square is a Klemperer Rosette which is a number of bodies rotating at an equal distance from a common center. Klemperer Rosettes don't normally occur in nature because they're unstable. Any tiny perturbations in the gravitational forces will be amplified, so it doesn't take long before the square falls apart.
(From here on the videos may be sped up.)
A hand-crafted, four-particle, "solar system":
Next up is a bigger test of over 7,000 particles. All the particles quickly collapse into a single "sun", which is anti-climactic:
Adding rotation to the particle cloud makes a big difference, allowing more structure to form:
Next steps: I'm interested in simulating how a solar system forms spontaneously from a cloud of dust and gas, so the plan is to add an option for new particles to continue falling onto the system for a long period of time.
- GLFW
- csv-parser (included)
- glad (included)
- glm (included)
- Command-line options.
- Decouple the particle simulation from the graphical renderer.
- Numerical Integration.
- CUDA acceleration.
- 3-D.






