Three-Body Problem Simulator Back
Classical Mechanics / Chaos

Three-Body Problem Simulator

Visualize gravitational interactions among three bodies in real time. Explore special solutions like the figure-8 periodic orbit and Lagrange stable triangle, through to the chaotic general case proven by Poincaré in 1890.

Presets
Parameters
● Mass m₁
● Mass m₂
● Mass m₃
Gravitational constant G
Trajectory length
pt
Playback Controls
Trajectory Comparison
Results
Total energy E
Angular momentum L
0.00
Elapsed time t
Three-body simulation — real-time state values
Body x y vx vy
Body 1 (Blue)
Body 2 (Pink)
Body 3 (Green)
Body 1 (Blue) Body 2 (Pink) Body 3 (Green)
Energy breakdown
Kinetic energy:
Potential energy:
Total energy:
Angular momentum (z component):
Theory & Key Formulas

Gravitational acceleration acting on each body $i$:

$$\ddot{\mathbf{r}}_i = G \sum_{j \neq i}\frac{m_j (\mathbf{r}_j - \mathbf{r}_i)}{|\mathbf{r}_j - \mathbf{r}_i|^3}$$

Total energy (conserved quantity):

$$E = \frac{1}{2}\sum_i m_i |\dot{\mathbf{r}}_i|^2 - G\sum_{i < j}\frac{m_i m_j}{|\mathbf{r}_i - \mathbf{r}_j|}$$

Angular momentum (conserved quantity): $\mathbf{L}= \sum_i m_i (\mathbf{r}_i \times \dot{\mathbf{r}}_i)$

Numerical integration: Leapfrog (Störmer–Verlet), $\Delta t = 0.0005$

Poincaré (1890) proved that the general three-body problem has no analytical integral. This became the starting point of chaos theory.

Feedback
Please share your feedback or report issues

What is the Three-Body Problem?

🙋
What exactly is the "three-body problem"? I've heard it's famously unsolvable, but this simulator seems to be solving it just fine.
🎓
Great question! Basically, the "unsolvable" part means there's no single, neat mathematical formula that predicts the positions of all three bodies for all time, unlike with two orbiting bodies. In practice, we use computers to calculate the motion step-by-step, which is exactly what this simulator does. Try moving the "Trajectory length" slider to see how the paths evolve over time—they can become incredibly complex and chaotic.
🙋
Wait, really? So it's all just computer calculation? What are those "conserved quantities" mentioned, like energy?
🎓
Exactly. Even though the paths are chaotic, the total energy and angular momentum of the system must stay constant—that's a fundamental law of physics. The simulator checks this. For instance, if you set all three masses to be equal using the sliders and find a stable "figure-8" orbit, you'll see these conserved quantities barely change. If they drift, it tells us about the numerical accuracy of our step-by-step calculation.
🙋
So the masses are the main thing we control. What happens if I make one body, like m₁, super heavy compared to the others?
🎓
That's a fantastic experiment to run! When one mass dominates—like the Sun in our solar system—the problem becomes more predictable, almost like a two-body problem with small perturbations. Adjust the `m₁` slider to be 100 times larger than m₂ and m₃. You'll likely see the two smaller bodies orbit the large one in complex, but somewhat regular, patterns. This is a common case in astronomy, like a star with two planets.

Physical Model & Key Equations

The motion of each body is governed by Newton's Law of Universal Gravitation, summed over the influence of the other two bodies. This gives us a set of second-order differential equations for the acceleration of each body.

$$\ddot{\mathbf{r}}_i = G \sum_{j \neq i}\frac{m_j (\mathbf{r}_j - \mathbf{r}_i)}{|\mathbf{r}_j - \mathbf{r}_i|^3}$$

Here, $\ddot{\mathbf{r}}_i$ is the acceleration vector of body $i$, $G$ is the gravitational constant (which you can adjust in the simulator), $m_j$ is the mass of another body, and $\mathbf{r}_j - \mathbf{r}_i$ is the vector pointing from body $i$ to body $j$.

Despite the chaotic motion, the system conserves total mechanical energy, which is the sum of kinetic and potential energy. This is a crucial check for the simulation's numerical accuracy.

$$E = \frac{1}{2}\sum_i m_i |\dot{\mathbf{r}}_i|^2 - G\sum_{i < j}\frac{m_i m_j}{|\mathbf{r}_i - \mathbf{r}_j|}$$

The first term is the total kinetic energy (energy of motion). The second term is the total gravitational potential energy (energy of position, which is negative because gravity is attractive). In a perfectly accurate simulation, $E$ remains constant.

Real-World Applications

Celestial Mechanics & Solar System Stability: The long-term stability of our solar system is an N-body problem. While largely stable, tiny gravitational kicks between planets over millions of years require three-body calculations to model. This helps us understand past and future orbital migrations.

Spacecraft Orbit Design: Mission planners use the three-body problem to design fuel-efficient trajectories. For instance, the James Webb Space Telescope orbits the Sun-Earth Lagrange point (L2), a special solution to the three-body problem where gravitational forces balance, allowing a stable observing position.

Binary Star & Exoplanet Research: Many exoplanets are discovered in binary star systems (two stars orbiting each other). A planet in such a system is a classic three-body problem. Simulating these dynamics helps astronomers interpret observational data and determine if an orbit could be stable enough for life.

Advanced Numerical Methods: Solving this problem for millions of bodies (like in galaxy simulations) requires smart algorithms like the Barnes-Hut tree code or Fast Multipole Method. The three-body problem is the foundational testbed for developing and validating these crucial CAE and computational physics techniques.

Common Misconceptions and Points to Note

First, do not assume that "simulation results are always correct". This tool is a form of numerical computation, and the leapfrog method is not a panacea. Particularly when celestial bodies undergo an extremely close approach or "near-miss," calculation errors can increase rapidly, leading to physically implausible outcomes like unrealistically fast rotation or bodies being ejected. In practical applications, handling such singularities requires special techniques.

Next, a common misunderstanding is that "the presets are special, magical solutions". The Figure-8 solution is indeed beautiful, but it represents a very delicate equilibrium state achieved through perfect tuning of mass ratios, positions, and velocities. The probability of such a configuration occurring naturally in the real universe is vanishingly small. The correct way to view it is as one mathematically possible solution among many.

Regarding parameter settings, a useful tip is to keep non-dimensionalization in mind. For example, instead of setting masses to 1, 10, and 100, try normalizing the total mass to 1 and using values like (0.1, 0.3, 0.6). This makes it easier to compare and understand the system's behavior. The same applies to distance and time; using a mental scale where, for instance, the Sun-Earth distance is 1 (astronomical unit) and one year is 1 can help ground the simulation in reality.