Three-Body Simulator

🌌 Three-Body Problem Handbook
📌 1. Initial Values
In the 2D three-body problem, each body has 4 degrees of freedom: position (x, y) and velocity (vx, vy). Three bodies give 12 initial values, plus 3 masses = 15 parameters.
1.1 Position (x, y)
Coordinates in the 2D plane. In this simulation, 1 unit ≈ 200 pixels on the canvas.
- Center of mass: weighted average of positions. If
Σ mᵢ·rᵢ = 0, the center of mass is at the origin. - Figure-8 solution: center of mass at origin, so the system as a whole does not translate.
1.2 Velocity (vx, vy)
Velocity components in x and y. Affects trajectory shape and total energy.
- Zero total momentum:
Σ mᵢ·vᵢ = 0makes the center of mass stationary — a necessary condition for the figure-8 solution. - Zero total angular momentum:
Σ mᵢ·(rᵢ × vᵢ) = 0prevents overall rotation.
1.3 Mass (m)
The gravitational "charge" of a body. Larger mass = stronger gravity.
- Equal masses (1:1:1): prerequisite for the figure-8 and Lagrange solutions.
- Extreme mass ratio (e.g., 10:1:1): approximates a "binary + planet" system, more stable.
- Normalize total mass = 3: rescale all masses proportionally so their sum is 3.
Discovered by Moore (1993) and Chenciner-Montgomery (2000). Three equal-mass bodies chase each other along a single figure-8 curve, with period
T ≈ 6.325.⚛ 2. Physics
2.1 Specific Energy
Energy per unit mass of each body — the key indicator for escape:
Note: the simulation introduces a softening parameter SOFTENING = 0.02. In practice rᵢⱼ = √(Δx² + Δy² + SOFTENING²) to avoid numerical singularities at close encounters.
- Eᵢ < 0: Bound. The body lacks enough energy to escape.
- Eᵢ > 0: Escaped. The body's speed exceeds the local escape velocity and it flies to infinity.
- Eᵢ = 0: Critical. The body just reaches infinity with zero speed.
2.2 Total Force
Body i experiences the vector sum of gravitational pulls from the other two:
2.3 Gravity Field and Equipotential Lines
The three-body gravitational potential is:
Equipotential lines (Gravity Field toggle) are extracted via Marching Squares. Deeper potential wells produce denser, brighter contours.
🪐 3. Known Periodic Solutions
3.1 Lagrange Equilateral Solution (1772)
Three bodies always form an equilateral triangle rotating about their common center of mass.
- Stability: depends on mass ratio. For equal masses it is unstable!
- Routh (1875) showed stability requires
β < √2. For equal masses β = √3 ≈ 1.732 > 1.414, hence unstable.
3.2 Euler Collinear Solution (1767)
Three bodies always remain collinear, rotating about the center of mass.
- Unstable: collinearity is a "needle-tip balance" — any perpendicular offset creates a transverse force that grows.
3.3 Figure-8 Solution (2000)
Three equal-mass bodies chase each other along the same figure-8 curve.
- Unstable, but the instability rate is slower than the previous two (characteristic exponent λ ≈ 0.01~0.05).
✧ 4. Concurrence Theorem for Three Gravity Lines
4.1 Definition
The reverse extension of each body's net force direction is called its "gravity line." Do the three lines meet at a single point?
4.2 Mathematical Result
They do so only when:
[d₁₂, F₂]·[F₁, F₃] = [d₁₃, F₃]·[F₁, F₂]4.3 When Do They Concur?
- Collinear configuration: the three lines coincide (degenerate concurrence).
- Lagrange equilateral solution: all three lines pass through the center of mass.
- Figure-8 at specific phases: discrete concurrence 2–3 times per period.
Because
F₁ + F₂ + F₃ = 0 (net force is zero), the three gravity lines statistically point toward some interior region. The three intersections are usually close together, but strict concurrence occurs only in the cases above.🚀 5. Key Factors for Escape
5.1 Core Mechanism: Energy Redistribution
The fundamental cause of escape in a three-body system is energy redistribution via gravitational interaction:
Total energy is conserved, but individual energies are not — gravitational work transfers energy among bodies.
5.2 Three Escape Mechanisms
| Mechanism | Description | Timescale |
|---|---|---|
| Gravitational Slingshot | A binary transfers energy to a single star, which escapes | Single encounter |
| Chaotic Amplification | Tiny initial differences amplify exponentially, randomly falling into escape regions | Several characteristic times |
| Resonance Pumping | Periodic resonances accumulate energy | Multiple encounters |
| Numerical Error (non-physical) | False escape (caused by accumulated integration error, not real physics) | Depends on precision |
5.3 Ultimate Fate
For the vast majority of initial conditions, the system eventually disintegrates into a binary plus one escaped star.
5.4 Escape Detection in This Simulation
The specific-energy panel shows Eᵢ in real time:
- Bound: green energy bar, labeled "Bound"
- Escaped: card turns red and blinks; the body turns red with a pulsing halo and "⚠ Escape" text
- Hysteresis: E must remain above threshold for several frames before escape is confirmed, avoiding jitter during close encounters
🌪 6. Chaos and Stability
6.1 What Does "Unstable" Mean?
Stability of a dynamical system is quantified by the Lyapunov exponent λ:
- λ < 0: Stable. Perturbations decay.
- λ = 0: Neutral. Perturbations persist.
- λ > 0: Unstable. Perturbations grow exponentially:
δ(t) ~ δ(0)·e^(λt).
6.2 The Chaotic Nature of the Three-Body Problem
This is the fundamental reason the three-body problem is called "chaotic."
6.3 Stability Comparison
| Solution | Lyapunov exponent | Visual instability time |
|---|---|---|
| Euler collinear | λ ≈ 0.1~0.5 | Disintegrates within a few periods |
| Lagrange equilateral | λ ≈ 0.1~0.3 | Disintegrates within tens of periods |
| Figure-8 | λ ≈ 0.01~0.05 | Disintegrates after hundreds of periods |
🎮 7. Usage Guide
7.1 Canvas Controls
- Drag: pan the view
- Scroll / Pinch: zoom
- Auto Fit: adjusts the view to all three bodies (smooth follow, exits when you interact)
- Reset View: back to initial zoom and center
7.2 Display Toggles
| Toggle | Shows |
|---|---|
| Gravity Field | Potential-well halos + equipotential lines (computed in physical coordinates) |
| Body Trails | Recent trajectories (solid lines, no glow) |
| Body History Trails | Full trajectory history (dashed lines, persistent) |
| Intersection Trails | Recent intersection paths (yellow solid lines) |
| Intersection History | Full intersection history (yellow dashed lines, persistent) |
| Intersection Markers | Intersection dots + strict-concurrence ★ |
| Force Arrows & Gravity Lines | Net force vectors + forward extension dashes for each body |
7.3 Initial Values
- Mass (m₁, m₂, m₃): golden input fields, change the gravitational strength
- Position (x, y): body coordinates
- Velocity (vx, vy): velocity components
- Presets: Figure-8, Lagrange Equilateral, Euler Collinear, Random Perturbation
- Normalize Total Mass: rescale masses so their sum = 3
- Apply & Reset: restart with the new initial conditions
7.4 Observation Tips
1. Select the "Lagrange Equilateral" preset
2. Watch the specific-energy panel: all E values start negative
3. At the instability moment, one E jumps positive (hysteresis prevents false positives)
4. That body turns red on the canvas with a pulsing ring
5. Use "Auto Fit" to zoom out and track the escaping body
1. Click the "Random Perturbation" preset
2. Each click produces slightly different initial values
3. Watch how completely different the trajectories become — that's sensitivity to initial conditions
Φ_total = −G·Σ mᵢ/rᵢ · F = m·a · E = ½|v|² + U