N-body simulation - Blue Planet

λ Serpentis II

[Java in the browser being long dead, the applet has now been rewritten to use OpenSilver.]

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).

The relative angle of the two moon at the start of the simulation can be controlled by the spinner, to establish the angular separation in degrees, with the outer moon (grey) moving around its orbit (the outer circle); while the inner moon (green) remains fixed in its orbit (inner circle) as the angle is adjusted. The numeric value can be directly typed in and is accepted when the `Enter` key is pressed.

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 excursion by either moon.

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

The C#/OpenSilver implementation is here.

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.