Three Body Problem

This sketch simulates a three-body system in a two-dimensional space using p5.js. It is inspired by the book and TV Series titled "3 Body Problem"

To go straight to the simulation, please scroll to the simulation below.

Chaos theory

The system consists of three celestial bodies that interact with each other through gravity, influencing their positions and movements over time. This is a classic example of a chaotic system, where small changes in initial conditions can lead to vastly different outcomes. The simulation demonstrates how the three-body system evolves dynamically, showcasing the complex and unpredictable nature of chaotic systems.

Setting up the simulation

The code is based on a previous implementation of orbital mechanics. The main requirements for this simulation are:

  1. The 3 celestial bodies should be of comparable mass
    This problem will not work if one or more bodies have a mass that is significantly different than the others. We can think of the earth, moon and sun, which is not a 3 body problem because the sun is so massive that it dominates the system.
  2. One body should not be too far away from the other two
    The bodies should be close enough to interact with each other. If one body is too far away, it might not be influenced by the other two, leading to a 2 body system instead


Chaotic systems can easily get out of control and lead to unstable or unpredictable behavior. Should it look odd, please use the "Replay" button to restart the simulation.