Skip to content
N-Body Gravitational Dynamics Simulation via Leapfrog Integration
C++ Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
data
Body.cpp
Body.hpp
Main.cpp
Makefile
Physics.cpp
Physics.hpp
README.md
planets.txt
sim.gif

README.md

N-Body: Two-Dimensional N-Body Gravitational Dynamics Simulation

Description

For each of the N particles...

  1. Calculate the pairwise gravitational force via Newton’s Universal Law of Gravitation and the principle of superposition.
  2. Use Newton’s Second Law to calculate the particle’s acceleration.
  3. Assume the above acceleration is constant within the time interval Δt and update the velocity: v = v + Δt a.
  4. Assume the above velocity is constant within the time interval Δt, and update the position: r = r + Δt v

Usage

    ./NBody <total-time> <time-step>
Options:
  - total-time: The duration of the entire simulation.
  - time-step: delta_t, the incremental change in time

Build

Use the Makefile to build the Nbody executable then run the simulation by loading the initial conditions from planets.txt and passing the total-time & time-step values as command line arguments.

e.g. ./NBody 157788000.0 25000.0 < planets.txt

Dependencies

libsfml was used for drawing the particles.

You can’t perform that action at this time.