← Back to district

Gravity simulator

Gravity simulator demonstration showing orbiting bodies and their trails on a spatial gridScientific software

C++ desktop simulation

An interactive orbital sandbox

An interactive two-dimensional gravitational simulator with body selection, camera tracking, asteroid launch controls, collision merging, and adjustable simulation speed.

C++SFMLVelocity VerletCollision detection

System architecture

  1. 01Body states
  2. 02Pairwise gravity
  3. 03Velocity Verlet
  4. 04Collision merging
  5. 05Interactive rendering
Orbital simulation in motion

Orbital simulation in motion

Recorded demonstration of the gravity simulator, with orbiting bodies and visible motion trails.

01

Numerical dynamics

The simulation calculates pairwise gravitational acceleration and advances the system using velocity Verlet. Close encounters and fast flybys limit the timestep through bounded subdivisions, helping resolve rapid changes in the interaction geometry.

02

Collision handling

Swept collision checks identify contact during the position update. Merged bodies use mass-weighted position and velocity; the implementation also accounts for kinetic energy lost in the merge. The model is a Newtonian sandbox, not a relativistic astrophysics solver.

03

Interactive experimentation

The desktop interface supports launching bodies, changing launch mass and radius, selecting and following a body, pausing, resetting, and inspecting performance or accuracy displays. The animation shows the desktop simulator in operation; the linked repository contains the application. A live browser simulation is deferred.