Numerical Integration
The three-body problem generally has no analytical solution, but it can be solved numerically — time is discretized and body positions are computed step by step.
Euler's Method
The simplest numerical integration method. At each step, acceleration is assumed constant: position and velocity are updated along the tangent line to the true trajectory. Local truncation error (per step) — O(h²), where h is the time step. Global error (after integrating over a fixed interval) — O(h). To halve the error, you must halve the step size. The method is not symplectic: energy monotonically increases over time, causing orbits to blow up.
Runge-Kutta 4th Order
The classical fourth-order Runge-Kutta method. Each step computes four intermediate accelerations: at the start, at two trial midpoints, and at the end. These are then averaged with weights (1:2:2:1). Local error — O(h⁵), global — O(h⁴). To halve the error, you need only reduce the step by ~16%. But the method is not symplectic: over long timescales, energy slowly drifts (usually downward). RK4 is a good choice for short intervals or when high per-step accuracy is needed.
Velocity-Verlet
A second-order symplectic integrator. Unlike Euler and RK4, Velocity-Verlet preserves the geometric structure of phase space (the symplectic form). «Symplectic» means the method conserves phase space volume — analogous to area preservation in phase space. In practice, this yields energy conservation over long timescales: energy does not systematically drift, but merely oscillates around the true value. The method is also time-reversible. Velocity-Verlet is the gold standard for celestial mechanics. Its global error is O(h²), but due to its symplectic properties, it outperforms RK4 of the same order over intervals of thousands or millions of steps.
Comparison
Euler's method accumulates error quickly and does not conserve energy. RK4 is accurate over short intervals but does not systematically conserve energy. Velocity-Verlet is the best choice for gravitational problems: it is symplectic (conserves phase space volume) and provides good energy conservation over long times.
Simulation
Switch the integration method and observe how well the orbit is preserved.
A few words about our simulator and the challenge of orbit rendering: we are balancing accuracy and performance. Accuracy is determined by:
dt— the smaller, the more accurate- integration method — Velocity-Verlet gives the best energy conservation, RK4 is a balance, Euler is the crudest
soft— the smaller, the more accurate gravity at close distances
Performance is affected by stepsPerFrame(how many dt steps per frame) and dt itself: the smaller the step or the more steps, the higher the CPU load.
And finally G — gravitational constant, zoom — visual scale.
Thus, the described integration methods at the accuracy settings used in the simulator provide orbit stability for approximately 3000 frames. Increasing accuracy further may cause the page to freeze (or perhaps you have already encountered this).