N-body simulation - Blue Planet

λ Serpentis II

[Java in the browser is moribund, if not actually dead, given the constant stream of exploits being found. JavaScript is the new hotness, so I'm planning a rewrite. Don't hold your breath.]

The simulation uses a generalised N-body algorithm, converted to Java from the Fortran code by Sverre Aarseth and given in Binney & Tremaine's Galactic Dynamics. Two instances are used in this applet : the left hand display shows the system with the moons having negligible mass, and velocities for circular orbits as stated; the right has the moons with mass (and the planet with corresponding velocities to keep the centre of mass stationary in the display).

Sorry, you need a browser that supports canvas or SVG (Opera 9, Firefox 1.5, etc…)


The relative angle of the two moon at the start of the simulation can be controlled by the slider below (the figure above giving the separation in degrees), with the outer moon (grey) moving around its orbit (the outer light blue circle); while the inner moon (green) remains fixed in its orbit (inner light blue circle).

The system is set running by hitting the button. The time elapsed in days is given in the line below the frame, plus the energy (in arbitrary units) of the massive system - which should remain constant, but will vary slightly due to computational noise. A scale bar is given, and the displays rescale to fit any extreme excursione by any moon.

If a moon is ejected from the system, or collides with another body this will be logged above the status line.

While I'm re-writing the applet in modern JavaScript, you can look at the original Java implementation.

Download the Java source

Download the Java class archive which can also be run as a Java application by


java -cp /path/to/nbodyzip.zip Nbody

22-Nov-02 - Finally got round to fixing a minor but annoying bug (where I resized the display window to the wrong size on occasion), and took the opportunity to tidy up the control panel part, and allow for collisions (assumed inelastic, for simplicity, as it's still "Game Over" at that point).

It's still all Java 1.0.2, because it doesn't need any more.