This project implements a basic N-body gravitational simulation using Newtonian physics.
It models the interaction between multiple celestial bodies and visualizes their motion over time.
This implementation focuses on correctness, reproducibility, and clarity, which are essential for real-time physics simulations.
The work serves as a foundational step toward building a real-time AR gravity sandbox in Unity, where users can create and explore planetary systems interactively.
The simulation is based on Newton’s Law of Gravitation:
F = G * (m₁ * m₂) / r²
Where:
- F → gravitational force
- G → gravitational constant (scaled)
- m₁, m₂ → masses
- r → distance between bodies
The simulation uses semi-implicit Euler integration:
-
Velocity update:
v = v + a * Δt -
Position update:
x = x + v * Δt
A small softening factor is added to avoid numerical instability at very small distances.
The simulation is deterministic for fixed initial conditions and time step, ensuring reproducible results.
- 3-body system:
- 1 central massive body (Sun)
- 2 orbiting bodies (Planets)
- The Sun is fixed to simplify visualization
- Demonstrates gravitational interaction and orbital motion
Running the simulation generates:
output.csv→ position data over timetrajectory_plot.png→ visualization of orbital paths
- Python 3.11.0
- numpy
- matplotlib
Install dependencies:
pip install -r requirements.txt