Gravity Simulator

This free gravity simulator runs Newtonian gravity in real time. Load the Sun, Earth and Moon, a binary star, the famous figure-8 three-body orbit or a chaotic tangle of worlds — then drag on empty space to slingshot in new planets and watch their orbits play out. Nothing is uploaded; the whole N-body simulation runs on your device. Free on LK Forge — no sign-up.

You are in the Physics lab.

Drag to launch · scroll to zoom · tap a body or use Follow to track it
Bodies0
Elapsed time0.0 yr
Kinetic energy0
Potential energy0
Total energy0
PresetSun-Earth-Moon

Total energy over time. Gravity is conservative, so with a good integrator this line stays flat on the dashed baseline — that's energy conservation. Watch it drift during close encounters or on the chaotic preset.

The three-body problem has no general solution. Two bodies orbiting under gravity trace a tidy, predictable ellipse — but add a third and there is no closed-form formula for their motion. The system is chaotic: shift a starting position by a hair and the orbits diverge into a completely different future. Load the Chaotic three-body preset and reset it a few times to see it.

Reading the simulation

What the orbits, the trails and the energy trace are telling you.

1

Every pair pulls on every pair

There is no special "centre" — each body attracts every other with an inverse-square force, so the pulls all add up. A heavy sun dominates the sum and the light bodies fall into orbits around it, while the small crosshair marks the system's barycentre, the balance point the whole system circles. The Gravity strength slider scales that force up or down.

2

Trails reveal the shape of the orbit

Turn Trails on and each body paints its recent path. A light planet around a heavy star traces a clean, closed ellipse that keeps repeating; give bodies comparable masses and the trails scribble and wander — the signature of a chaotic orbit that never repeats. Compare the Sun-Earth-Moon and Chaotic three-body presets to see both at once.

3

Slingshot a planet, and watch energy hold

Drag on empty space to slingshot a new body — the longer the drag, the faster the launch. As it swings past a star its kinetic and potential energy trade back and forth in the readouts, yet the total energy barely moves and the trace stays flat: gravity conserves energy, and the integrator respects it.

How It Works

Real Newtonian gravity, integrated step by step in your browser.

1

Newton's law of gravitation

Every body attracts every other with a force proportional to the product of their masses and inversely proportional to the square of the distance between them. Each frame the simulator sums those pulls to get the acceleration on each body, with a small "softening" term so near-collisions stay numerically stable.

2

The Velocity-Verlet integrator

Positions and velocities advance with Velocity-Verlet: compute accelerations, nudge the positions forward, recompute accelerations at the new positions, then update velocities using the average. This time-symmetric scheme conserves energy far better than naive stepping, so orbits don't spiral out over time.

3

Stable vs chaotic orbits

A light planet around a heavy star settles into a near-perfect ellipse. Give several bodies similar masses and the mutual tugging turns chaotic — orbits swing wildly, and a body may even be flung out of the system. Drag on empty space to launch your own planet and see which regime it lands in.

How is gravity calculated in the simulator?
Gravity in this simulator comes from Newton's law of universal gravitation: every body pulls on every other body with a force proportional to the product of the two masses and inversely proportional to the square of the distance between them. The simulator sums those forces for each body and advances the motion with a Velocity-Verlet integrator, which keeps orbits from drifting in energy the way a naive step would. A small softening term is added to the distance so bodies that pass very close don't blow up numerically.
What is the three-body problem?
The three-body problem asks how three masses move under their mutual gravity. Unlike the two-body problem, it has no general closed-form solution: for almost all starting conditions the motion can only be found by numerical integration, and tiny changes in the initial positions or velocities lead to wildly different orbits. The figure-8 and chaotic presets here are both three-body setups, and running them one after the other shows how differently the same problem can behave.
What is the figure-8 orbit?
The figure-8 is a rare stable solution to the three-body problem, discovered by Cris Moore in 1993 and proven by Chenciner and Montgomery in 2000. Three equal masses chase each other around a single figure-eight-shaped path. It is one of the few known periodic three-body 'choreographies', and it is included here as a preset.
Is energy conserved in the simulation?
Energy in the simulation is very nearly conserved. Gravity is a conservative force, so the total energy of the system — the sum of every body's kinetic energy and all the pairwise potential energy — should stay constant. The Velocity-Verlet integrator used here is time-symmetric, which keeps that total from drifting the way a naive step would, so the energy-vs-time trace stays close to flat on the dashed baseline. It only wobbles during very close encounters or in the chaotic preset, where the tiny numerical timestep struggles to keep up. The readouts show the kinetic, potential and total energy separately, so you can watch energy trade between motion and gravity while the sum barely moves.

Teaching or blogging about physics? You can embed this on your own site free — one line of code, no sign-up.

Classroom activity

A ready-to-assign lab using the simulation above. Free to use — nothing to install or sign up for, and no student data leaves the browser.

High school, College10–20 minInteractive simulation

Learning objectives

  • Apply Newton's law of gravitation to orbital motion.
  • Relate orbital speed and radius.
  • Recognize Kepler's laws in the simulated orbits.

Variables to change

  • Mass of central body
  • Initial speed
  • Initial position
  • Number of bodies

Procedure

  1. Place one planet and give it a speed that produces a near-circular orbit.
  2. Reduce the speed and observe the orbit shape; then increase it.
  3. Increase the central mass and observe the effect on the orbit.

Observations

Note how orbit shape (circle, ellipse, escape) changes with initial speed and central mass.

Questions

  1. What shape is a bound orbit in general?
  2. How does gravitational force depend on distance?
  3. What happens if the initial speed is too high?
  4. State Kepler's second law and what it implies about speed.
  5. How does increasing the central mass change a stable orbit at fixed radius?

Explanation

Gravity provides the centripetal force that holds bodies in orbit. The inverse-square law yields elliptical bound orbits (Kepler’s first law) and equal-area sweeping (second law). Too much speed and a body escapes; more central mass demands faster orbits.

Answer key (for instructors)
  • 1. An ellipse, with the central body at one focus (a circle is the special case).
  • 2. It follows an inverse-square law: F = G·m₁·m₂/r².
  • 3. The object escapes on an unbound (parabolic or hyperbolic) path once it exceeds escape velocity.
  • 4. A line from the planet to the star sweeps equal areas in equal times, so the planet moves fastest at closest approach (perihelion).
  • 5. It increases the required orbital speed; stronger gravity demands faster motion to stay in orbit.

Educators: link or embed this simulation freely in your LMS or course guide.

Add This Gravity Simulator to Your Website

Put the Gravity Simulator on your own page — free, no sign-up, no watermark. It runs entirely in your visitors' browsers. Copy the snippet and paste it into your page's HTML.

The credit line under the widget links back to LK Forge — please keep it so others can find it too.