Inspiration
Since the physics club is one of the organizing bodies, I thought it appropriate to select a physics based prompt. Simulating a couple of bodies is easy in O(n^2) time---especially in a very high level language. This is why I wanted to use C to build a more powerful simulation.
What it does
The simulations spawns several thousand randomly generated particles inside an ellipse. The particles each have a random mass, position within the boundaries, and starting velocity. The simulation then runs, animating as the particles exert gravitational forces on one another. Patterns quickly emerge and we can see the formation of what look like galaxies. This demonstrates how and why these shapes show up in the cosmos.
(I can get ~100,000 particles simulated on my laptop with a couple frames per second)
How we built it
The entire simulation is built in C. Since C is a compiled language which allows for low-overhead and direct memory control, it was the ideal candidate to build this. The speed of a compiled language is needed to keep the simulation performant when dealing with tens of thousands of particles.
Each particle is represented by a struct containing vectors (structs themselves) for position, force, acceleration, and velocity. A Barnes-Hut tree is then constructed to bring the runtime complexity from O(n^2) down to O(n log n) at the cost of space.
On top of leveraging Barnes-Hut approximation, a number of other optimization tricks were used to squeeze as much performance out of the simulation as possible. These include everything from pointer math to using Quake's fast inverse square root approximation.
Log in or sign up for Devpost to join the conversation.