A couple of weeks ago I made a post about the classical three-body problem, which involves determining the motion of three masses interacting via gravity over time.

In that simulation, the three masses were restricted to a plane. Even though we live in three spatial dimensions, a two-dimensional model for celestial orbits isn’t such a bad approximation – the orbits of masses in celestial system are often within a few degrees of the same plane.

In the simulation above I’ve built in a third spatial dimension and modeled a system in which the masses do not stay within the same plane. In this simulation, the green and red bodies are 9 and 13 times more massive than the blue body, respectively.

The Mathematica code for this one was a bit long, so I’ve posted it here.