Orbital Mechanics Sandbox: N-Body Gravity Simulation with Orbit Trails

Integrates the motion of up to ten bodies under mutual gravity in two dimensions and draws their orbit trails and final state.

Use the tool

Why this tool exists

Orbits are easy to describe and hard to picture. Enter a Sun, an Earth and a Mars in astronomical units, solar masses and years, and the trails show their ellipses. Change a speed and see how the orbit turns from circle to ellipse to escape.

The integrator is velocity Verlet (leapfrog), which keeps energy and angular momentum from drifting; both drifts are printed. The result was compared with a high-order solver, and it converges as the time step is reduced. Close encounters need a smaller step. The sample masses use the planet to Sun mass ratios from NASA data, and the speeds are circular-orbit values.

How to use it

  1. Enter one body per line: name, mass, x, y, vx, vy.
  2. Choose AU/solar mass/year units or arbitrary units with G = 1.
  3. Set the time step and total time.
  4. Read the final state and look at the trails.

Frequently asked questions

Why does G equal 4 pi squared?

In AU, solar masses and years that makes a circular orbit at 1 AU last one year, an idealisation.

Is it 3D?

No, two dimensions only.

How do I know the step is small enough?

Halve it and compare the final positions.

Can bodies collide?

There is no collision handling; a very close pass needs a tiny step.