Clever Quest Lab ← Labs

Gravity Simulator

Launch planets, moons and stars and watch Newton’s law of gravity shape their orbits.

In Add mode, press and drag in the view to launch a body; the arrow shows its starting velocity and a dashed line predicts its path. A tap places a body. Tap a body to select it. In Pan mode drag to move the view. Pinch, the mouse wheel or the plus and minus keys zoom; arrow keys pan. The F key follows the selected body and the C key follows the centre of mass.

Info

Bodies
0
Time
0
Total energy
0
Energy drift
0 %
Total momentum
0
CM speed
0
Actual speed
1×

No body selected

Mass
—
Speed
—
Orbit
—

Simulation

1.0×

New body

1 M

Tap to place a body or drag to launch it. With Circular orbit on, the drag only picks the direction.

Display & physics

Camera follows
40%

How to play

This is a sandbox for experimenting with orbits. Pick a scene above the view and it starts at once. To add a body, choose a mass, press anywhere in the dark view and drag. The arrow shows the starting direction and speed, and a dashed line predicts the path.

A tap places a body at rest. With Circular orbit ticked, the new body instead gets exactly the sideways speed it needs to circle that body, and dragging only chooses the direction.

Tap a body to see its mass, speed and orbit in the Info panel. Camera follows has three settings: Off, Selected body and Centre of mass. A followed target stays centred and trails are drawn as seen from it, which turns a moon’s wavy path into neat loops around its planet.

Controls

Mouse

Touch

Keyboard

How the physics works

Every body pulls on every other body according to Newton’s law of gravitation, F = G·m₁·m₂ / r², where r is their distance; with N bodies that is N(N−1)/2 pairs on every step. It uses G = 1 and plain units of length (L), mass (M) and time (T); in the inner planets scene 1 AU = 100 L, the Sun = 1000 M and one year ≈ 199 T. In near misses r² is replaced by r² + ε², where ε is a tiny softening length that avoids enormous forces.

Motion is advanced with the leapfrog method, also called velocity Verlet: half a kick from the current forces, a drift for one time step, new forces, then the second half kick. The step size is fixed per scene; the speed control only changes how many steps run per frame. Leapfrog is symplectic: its energy error wobbles around zero instead of piling up, so orbits stay closed for thousands of turns. Energy drift shows this error as a percentage.

When bodies collide they merge: the masses add up and the new velocity keeps the total momentum exactly the same, while some kinetic energy is lost, as in a real impact. After a merge, and whenever you add or delete a body, the reference energy starts again, so the drift always shows the integrator’s error since the last change.

For a circular orbit, gravity must supply exactly the force that bends the path into a circle, giving the speed v = √(G(M + m) / r). Kepler’s third law follows: T² ∝ a³, which is why outer planets are slower.

The centre of mass (barycentre) is the average position of all bodies, each weighted by its mass: Σ(m·r) / Σm. Gravity between the bodies only trades momentum among them, so for an isolated system the total momentum is conserved and the centre of mass moves in a straight line at constant velocity. Every body, even a heavy star, orbits this point, not the heaviest body itself. Following it removes the overall drift, so a binary star that sails across space draws two closed ellipses. Show centre of mass draws a cross-hair marked CM; the Info panel shows its speed.

Tips and strategy

Frequently asked questions

Is the inner solar system to scale?

Orbit sizes, shapes and periods are. Bodies are drawn far larger than life, orbits lie in one plane, and each planet starts at its closest point to the Sun.

Why is the energy drift not exactly zero?

Time steps are finite and numbers are rounded. Leapfrog keeps the error small and bounded; in the presets it stays far below one percent, and bigger values come from very close passes.

What makes the figure-eight special?

Most systems of three bodies are chaotic. In this rare solution three equal masses chase each other along one curve and return to their start after every period. It was found in computer experiments by Cristopher Moore in 1993 and proved to exist by Alain Chenciner and Richard Montgomery in 2000.

How many bodies can I add, and is my scene saved?

Up to 400. Your settings and scene are stored in this browser and restored next time; everything works offline.

More free games