Three Body Chaos Lab
The three-body problem and chaotic orbits, simulated in Maya: three masses, Newton's law of gravity and nothing drawn by hand.
- Lab
- Version 0.5.0
- Maya 2023 – 2027
- Windows
- Free
Why I built it
After watching the Netflix series 3 Body Problem, reading about the problem was not enough: I wanted my own interactive simulation, to see how such systems behave right inside Maya.
That is how Three Body Chaos Lab started: a Python tool for Maya that computes the motion of three bodies attracting each other and turns the result into ordinary Maya animation and trajectory geometry.
The one rule of the project: no trajectory is drawn in advance. Where every object is at every step comes straight out of the numerical solution of the equations of motion.
The problem
For each body we know three things: its mass \(m\), its starting position \(\mathbf r\) and its starting velocity \(\mathbf v\). We want the position of all three bodies over time,
given that every body is pulled by the other two.
Two bodies have an analytic solution: conic orbits, ellipses, parabolas and hyperbolas. The general three-body problem has no such universal, simple solution, so the motion has to be computed numerically.
The physical model
Classical Newtonian gravity. The force between two bodies is
For a simulation it is more convenient to compute the acceleration of body \(i\) directly:
So at every step each of the three bodies feels the other two.
The positions change all the time, so after every step all the accelerations are computed again from scratch.
Numerical integration
The state is advanced with Velocity Verlet, a symplectic integrator that suits mechanical and orbital problems well. The position is updated as
then the gravitational acceleration \(\mathbf a_{t+\Delta t}\) is computed again at the new positions, and the velocity is updated with the average of the two:
One step, in order:
And then it all repeats, thousands of times.
Why not Euler
The simplest possible step would be explicit Euler:
Plain Euler accumulates energy error quickly. In an orbital system that makes a stable orbit grow or fall apart for purely numerical reasons. Velocity Verlet preserves the structure of a mechanical system much better over long stretches of time.
The time step
One of the most important parameters is dt. With dt = 0.01 the state of the system is recomputed every 0.01 units of simulation time. The smaller dt, the more accurate the result:
and the more work there is, in proportion. The long periodic orbits use small steps over tens of thousands of iterations; the longest preset, Dragonfly, runs at dt = 0.00001 for 8.4 million steps.
Sampling for Maya, independent of the physics
A small dt brings a different problem. Sixty thousand physics steps could mean tens of thousands of curve CVs and animation keys in Maya. So the physics and the output are separated. Record Every N Physics Steps lets the physics run on every step, 1, 2, 3, 4, 5 …, while Maya only receives every Nth one, 10, 20, 30, 40 …
Physics dt = 0.0005
Record Every = 10 # same physical accuracy, about ten times less Maya geometry
Softening
When two point masses come very close, \(r \to 0\), the gravitational acceleration goes to infinity. In a discrete simulation that can turn into a huge velocity jump in a single step. A small gravitational softening keeps it finite:
Softening is not part of the ideal three-body problem: it is numerical stabilisation. For the periodic orbits it is set very small, 10⁻⁶.
Keeping an eye on energy
To know how far the numerical result is from the ideal mechanical system, the tool also computes the total energy. Kinetic and gravitational potential energy:
After a run, Energy Start and Energy End are compared:
That is what separates genuinely complex behaviour of the system from too much numerical error. For the presets, run with the tool's solver:
| Orbit | dt | Physics steps | Energy drift |
|---|---|---|---|
| Balanced triangle | 0.002 | 4,135 | 4.4×10⁻¹³ % |
| Figure eight | 0.005 | 1,265 | 6.7×10⁻⁸ % |
| Butterfly I | 0.0001 | 62,356 | 2.1×10⁻⁹ % |
| Moth I | 0.0005 | 29,788 | 2.2×10⁻⁸ % |
| Bumblebee | 0.00002 | 3,176,725 | 1.0×10⁻¹¹ % |
| Dragonfly II.17.B | 0.00001 | 8,368,334 | 5.9×10⁻⁹ % |
Chaos and sensitivity to initial conditions
A separate part of the project runs several almost identical systems side by side:
SYS00 Body C Position X = 0
SYS01 Body C Position X = 0.000001
SYS02 Body C Position X = -0.000001 # then ±2ε, ±3ε …
All of them are computed with one algorithm, the same dt, the same number of steps and the same physical parameters. The only difference is a microscopic change in the initial state. At first their motion is practically identical. After a while the differences start to grow, and that is how you get to see sensitivity to initial conditions.
Measuring the divergence
To put a number on it the tool uses RMS divergence. For each body, the distance to the same body of the reference system:
and then
One number that describes how far the whole system is from the reference. It is diagnostics only and never feeds back into the simulation.
Periodic solutions
Besides arbitrary chaotic starts, the tool carries several well-known periodic configurations.
Lagrange: the balanced triangle
Three equal bodies sit at the corners of an equilateral triangle. With exactly the right tangential velocity the whole system turns around the common centre of mass and keeps its shape. For a triangle of side \(a\):
where \(R\) is a body's distance from the centre of mass. A dynamic equilibrium, and a fragile one: with equal masses it is unstable, which is exactly what the chaos experiment above relies on.
Figure eight
Three equal bodies move along one shared figure-eight path. Their starting positions and velocities are chosen so that after one full period the system returns to where it started. It is one of the best-known modern periodic solutions of the three-body problem (Moore; Chenciner and Montgomery), and the animation at the top of this page.
More complex orbits
Later the tool got more intricate periodic solutions: Butterfly I, Moth I, Bumblebee and Dragonfly. The principle is no different from the figure eight, and the simulation algorithm stays exactly the same. Only the initial positions and velocities change. They all start from one symmetric convention:
So Butterfly is not a hand-drawn path. The script receives a set of initial conditions, runs an ordinary Newtonian simulation, and the shape of the orbit appears on its own. That is probably the most interesting part of the experiment.
Butterfly I, Moth I and Bumblebee are from the periodic orbits published by Šuvakov and Dmitrašinović (2013); Dragonfly uses re-converged centre-of-mass initial conditions.
The Maya tool
In short, the pipeline looks like this:
The current version is written in plain Maya Python, and the solver itself needs no external Python libraries. Its main parts:
- Body
- Mass, position, velocity and the position history.
- Physics
calculate_accelerations(),simulate(),total_energy().- Chaos
- Clone the system, perturb the initial state, measure the RMS divergence.
- Maya output
- Trajectory curves, animated spheres, materials, keyframe baking.
Visualisation
To keep crossing trajectories readable, each body owns a colour:
- Body A: red / orange
- Body B: cyan / blue
- Body C: violet
The colour is shared by the body and its trail. The reference system gets the brightest version; systems with perturbed initial conditions get muted versions of the same hues. Even with many crossings you can tell which body drew which piece of a trajectory.
What Maya does, and what it does not
Maya is not the physics solver here. It provides the UI, the visualisation, storage of the result, the curves, the animation baking, the camera and the render. The physics itself is computed by Python code.
Limits of the model
This is the classical, simplified three-body problem. The bodies are point masses. Not included:
- the physical radius of a body and collisions;
- tidal forces and deformation of the bodies;
- energy loss and drag;
- relativistic effects and radiation;
- external sources of gravity.
In other words, classical Newtonian N-body mechanics. For showing chaos and periodic orbits that is more than enough.
What came out of it
A fairly small Python solver turned into a little experimental lab inside Maya. You can change masses, starting positions and velocities; run several systems at once with microscopic perturbations and watch them separate; check energy conservation; explore the known periodic orbits; and keep everything as ordinary Maya animation.
The most interesting thing is that complicated-looking motion does not need complicated rules. All there is:
Yet with the right initial conditions that gives stable triangles, figure eights, Butterfly, Moth, Dragonfly, and chaotic trajectories that look as if somebody designed them on purpose. In fact they are just the result of one calculation repeated over and over:
And that was the real goal of the experiment: to see how complex a motion you can get from the simplest possible set of physical rules.
Try it
AZ Three Body Chaos Lab is free for every AZ Tools account. It lives in the Lab tab of the AZ Tools Manager (0.3.25 or newer) and in the Lab section of the AZ Tools menu in Maya. Pick a preset on the Bodies tab, press RUN VISUAL CHAOS, then Frame Results.
Get AZ Tools Manager
AZ TOOLS