# Modeling gravity for multiple objects

A former student, JH, recently corresponded with me about some simulations he'd done of a gravitational system. This problem is connected with many problems in physics including molecular dynamics and n-body problems. It is also of particular interest to game developers who need to simulate interacting particles.

Modeling Newtonian gravity for two objects is simple: two objects will orbit each other with circular, elliptical, parabolic, or hyperbolic orbits. So drawing the orbits is akin to graphing a function encountered in highs school algebra. But adding one or more bodies to your 2-body system will introduce chaotic behavior, unless you carefully chose your initial conditions. Below is a 3-body problem that demonstrates this.

As is often the case, despite the chaotic behavior, this is a relatively simple application of calculus (differential equations) to physics, accessible to high school students. In fact, the easiest way to start is with the Euler Method, introduced in AP calculus. A slight refinement called Verlet integration gives much better accuracy, used in the simulation above.

Newton solved the 2-body problem, and the 3-body problem has interested mathematicians since. There are interesting stable configurations discussed in this WolframScience article.

If you worked for SpaceX, NASA, or the Kerbal Space Program, you will need better accuracy than the Verlet provides. A next level of refinement is Beeman's algorithm.