Three-Body Problem
Three equal masses under Newton's gravity, stepped live by an action: the figure-eight orbit, and an equilateral triangle that turns and then breaks up into chaos.
Two bodies under gravity move on ellipses, and a formula gives their positions at any time. Three bodies have no such formula: except in special cases, the motion is chaotic, and the only way to follow it is to compute it step by step. This document does that, live.
The state is four lists of three numbers: the positions X , Y and the velocities U , V . The lists A and B hold the acceleration of each body, the sum of the pulls of the other two, each 1/r^2 toward the other body. An action runs every 30 ms and takes one step of velocity Verlet with time step h : it moves every body to X_n = X + hU + \frac{h^2}{2}A , computes the accelerations A_n at the new positions, and updates the velocities with the average of the old and new accelerations. This method conserves energy well, so an orbit does not slowly spiral in or out. The action also appends the new positions to the lists P_k , Q_k , which draw the trail behind each body.
The simulation opens on the figure-eight orbit, found numerically by Cris Moore in 1993 and proved to exist by Alain Chenciner and Richard Montgomery in 2000: the three bodies chase each other along one figure-eight curve, a third of a period apart, forever. The second preset action places the bodies on an equilateral triangle that turns at the speed that balances their attraction, a solution Lagrange found in 1772. For three equal masses this solution is unstable. One body starts 0.1% too fast, so the triangle turns about one and a half times and then breaks up into chaotic motion. Edit the lists X , Y , U , V and run the step to try your own starting positions.
After a Desmos graph by Amy.
JavaScript is required to view the interactive plot.