Loading the engineShared by all simulations, so the next one opens instantly.
The physics

Newton’s law of gravitation, applied to every pair of bodies at once. For two bodies the orbits are ellipses, parabolas or hyperbolas. From three bodies on there is no general closed-form solution, and the motion has to be followed step by step on a computer. This simulation does exactly that: it sums the pull of every body on every other one directly, with no approximation scheme for distant bodies.

What you see

Bodies are colored discs with fading trails; a central star is drawn in gray. The arrows in the background show the net gravitational field on a grid (switch them off with Force field). The view is a square 800 pixels wide. Bodies that leave it are not removed: they keep moving out of sight and keep pulling on the rest. Lengths are in pixels, and masses and time are in simulation units with G=800 by default.

Circular orbits: a star of mass 106 at the center and 9 planets at radii from 60 to 420 pixels, spread evenly in angle, each launched at the circular speed v=GM/r. The inner planets go around much faster than the outer ones, as Kepler’s third law T∝r3/2 requires. The planets are 500 to 2000 times lighter than the star, so they barely disturb each other. The outermost orbit reaches past the edges of the view.

Binary + asteroids: two stars of mass 5×105, 160 pixels apart, moving at half the speed of a circular binary. Their mutual orbit is an ellipse with eccentricity 0.5 that brings them to within about 53 pixels of each other. Fifty light asteroids start between 240 and 340 pixels from the center at 0.9 times the circular speed around the pair, on eccentric orbits that swing in toward the stars.

Chaotic triple: three equal masses of 105 at the corners of an equilateral triangle, 100 pixels from its center, with unequal velocities that add up to zero total momentum. Nothing about the setup is symmetric, and the first close encounter comes within a couple of seconds. The softening length is 12 pixels here, larger than the drawn bodies: each body acts like a soft cloud of that size, which keeps the closest passes smooth enough to integrate.

Cold collapse: 40 bodies of equal mass, at rest and spread uniformly over a disc of radius 280 pixels. With no motion to resist it, the whole disc falls in on itself in well under a second. As in the chaotic triple, the softening length is 12 pixels.

Rotating disk: a central mass of 2×106 surrounded by 60 light bodies at random positions between 50 and 310 pixels, each on a circular orbit around the center. Inner bodies overtake outer ones, and this differential rotation stretches any group of neighbors into an arc.

Governing equation

𝐫¨i=G∑j≠imj(𝐫j−𝐫i)(|𝐫j−𝐫i|2+ε2)3/2

The softening length ε keeps the force finite when two bodies pass through each other. By default the equations are integrated with the leapfrog scheme (velocity Verlet). It is symplectic, so for a well-resolved orbit the energy error oscillates instead of growing.

With Dark matter halo switched on, every body also feels

𝐫¨=−vh2𝐫r2+rc2,

where 𝐫 is measured from the center of the view, rc=15 pixels and vh=0.3G⋅106/200, which is 600 at the default G. The halo thus scales with G like the bodies’ own gravity. This is the pull of an isothermal halo with potential Φ=12vh2ln⁡(r2+rc2). On its own it would give every circular orbit the same speed vh, a flat rotation curve like those measured in spiral galaxies.

Parameters

Time step dt: the integration step, 0.0001 to 0.02 (default 0.00025), and Steps per frame, 1 to 32 (default 16), so that a frame advances the time by 0.004. Two bodies of mass m passing at the softening distance ε swing around each other in about ε3/2/2Gm, a few thousandths of a time unit for the heavier presets, and leapfrog keeps the energy only with steps well below that.

Number of planets: the number of bodies in Circular orbits, Cold collapse and Rotating disk, 2 to 60 (default 9). The other two presets have fixed numbers of bodies.

Gravitational constant G: 10 to 5000 (default 800). The presets compute their starting speeds from it, so after a Reset with a new value the circular orbits are circular again.

Dark matter halo: adds the halo force above; off by default.

Merging: when on, two bodies that overlap merge into one. The lighter one is absorbed, and momentum is conserved.

Softening ε (px): the length ε above, 0.1 to 20 pixels (default 4; Chaotic triple and Cold collapse use 12, so that their close passes stay slow enough for the step).

Integrator: leapfrog by default. Yoshida 4 is a fourth-order symplectic method; Runge-Kutta 4 is more accurate per step but lets the energy drift; Euler drifts fast.