Every body pulls on every other, just as Newton described. Start from the real solar system, three stars in a figure eight or two colliding galaxies, or build your own system and see what gravity does with it.
How to use the gravity simulator
Choose a scene from the list on the left. Drag to look around, scroll or pinch to zoom, and use the time controls at the bottom to speed up, slow down, pause or run time backward. Reset starts the scene again.
To add a body, choose one under Add a body: an asteroid, a moon, an Earth, a Jupiter, a red dwarf, a Sun or a black hole. Then:
- Click anywhere in space to place it on a circular orbit around the heaviest body, moving the usual way round.
- Drag from where you want it to start. The arrow sets its launch speed and direction: one astronomical unit of drag is 30 km/s, about Earth's speed around the Sun.
Click any body to see its mass, speed and nearest neighbour, to follow it with the camera, or to delete it. Press Esc to put the tool away, Space to pause and H to hide the controls for a clean view.
The scenes
| Scene | What to watch for |
|---|---|
| The solar system today | The planets start from their real positions and speeds at this moment, taken from the same tested ephemeris as the solar system simulator. Add a star or a black hole and see how quickly the orbits unravel. |
| Inner planets | Mercury's orbit is the most eccentric of the planets: it swings from 46 to 70 million km from the Sun. |
| Binary star with a planet | A planet circling two stars, like Kepler-16b. Its orbit wobbles with each turn of the stars. |
| Three stars in a figure eight | A rare stable solution of the three-body problem found in 1993 and proved in 2000: three equal stars chase each other around one figure-eight path. |
| Jupiter's Trojan asteroids | Asteroids 60° ahead of and behind Jupiter, at the Lagrange points L4 and L5, stay with the planet, while the main belt circles inside. |
| A star passes through | A Sun-like star crosses the outer solar system at 20 km/s. Which planets keep their orbits depends on how close it comes. |
| Two galaxies collide | Two spiral galaxies swing past each other, throw out tidal tails and fall back together. |
| Empty space | A single Sun. Build a system of your own. |
The physics
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: Newton's law of universal gravitation. The simulator adds up all of those pulls directly, pair by pair, with no shortcuts.
Positions and speeds are advanced with the leapfrog method, which alternates half-steps of acceleration with full steps of motion. Leapfrog is symplectic: it keeps energy from creeping up or down over long runs and conserves angular momentum exactly, so orbits stay closed instead of spiralling away. The size of each step adapts to the closest pair of bodies, and each step is chosen symmetrically in time (the method of Hut, Makino and McMillan, 1995), so eccentric orbits keep their energy through every close pass.
Units are astronomical units, days and solar masses. In those units the gravitational constant is the square of Gauss's constant, 0.01720209895, the same value astronomers used to compute planetary orbits for two centuries.
How we check it
The physics engine is tested every time the site is built:
- A planet at 1 AU from one solar mass completes its orbit in 365.26 days and returns to its starting point.
- Over a simulated century, energy changes by less than one part in a million and angular momentum by less than one part in a trillion.
- A comet on an orbit with eccentricity 0.91 passes within 0.05 AU of the Sun again and again with its energy held steady.
- The figure-eight returns to its starting positions after one period, keeps its energy to one part in a hundred million over ten periods, and runs backward exactly to where it began.
- Collisions conserve total mass and momentum.
Limits
This is Newtonian gravity: there is no relativity, so a black hole here behaves like any other very heavy point, without an event horizon. Collisions merge bodies rather than shattering them, bodies are drawn larger than life, and the galaxy stars feel the galaxies' cores but not each other. For the real, measured motion of the planets, open the solar system simulator.
Questions
Is this gravity simulator physically accurate?
It uses Newton's law of gravitation between every pair of bodies and a time-symmetric leapfrog integrator, the kind used in research N-body codes. We test it on problems with known answers: a planet at 1 AU around one solar mass takes one sidereal year, energy stays within a millionth over a century, and three stars in the figure-eight orbit return to their starting points after one period.
What does the energy change number mean?
In a closed system the total energy should never change. The simulator shows how far it has drifted since the scene started, which measures the accuracy of the calculation. It usually stays below a thousandth of a percent; a very close encounter can push it higher, and the simulator slows down near one to keep the error small.
Why do planets look so big?
At true scale a planet would be far smaller than a pixel at these distances, so bodies are drawn larger than life. Collisions use the drawn size: two bodies merge when their spheres touch, keeping their combined mass and momentum.
Can I reverse time?
Yes. The leapfrog integrator is time-reversible, so pressing the backward button runs the motion back the way it came. After a collision the merged body stays merged, because a collision cannot be undone.
How is the galaxy collision simulated with thousands of stars?
Each galaxy's mass sits in a softened central core, and its 6,000 stars move in that gravity without pulling on each other. This restricted method is how Alar and Juri Toomre first explained tidal tails in 1972, and it reproduces the long curved streams seen in real merging galaxies.