The term "n-body problem" generally refers to the problem of predicting the motion of planets, stars, moons, asteroids, or, more generally, celestial bodies. Although there's no known general analytical solution to this problem[1], it's easy to simulate the movement of those bodies approximately using Newton's law of universal gravitation.
It's a simple interactive n-body simulation that allows anyone to play with the initial parameters to see how it affects the bodies' orbits. Hopefully, somebody finds it as fascinating as I do to discover how simple changes in the initial parameters can lead to wildly different outcomes.
It's pretty hard to get a system with anything above 2 bodies to reach a stable state. In fact, it's so hard that mathematicians and scientists have been scratching their heads over this problem for decades. Here are a few interesting orbits that I managed to come up with (or stole from math papers) to help you get started:
To discover more interesting and stable 3-body system configurations, see this website which catalogued known stable configurations of planar 3-body system in a really neat way.
This website uses almost exclusively vanilla HTML and Javascript along with a few lines of CSS. It is served as a static website using Cloudflare Pages. The graphics for the simulation use the <canvas>
HTML element and the CanvasRenderingContext2D
interface for rendering. I also used Svelte to make the form for editing simulation parameters reactive. The entire source for this website is available here.
The complex patterns that appear out of seemingly simple initial parameters fascinate me. I also have a passion for programming and learning more about pretty much anything. Therefore, making this simulator seemed like the perfect opportunity to learn more about the Canvas API while having fun in the process. In fact, I ended up having so much fun with it, that I decided to add a form to make it easier for non-techy people around me to play with it and experience the same awe that I felt at the emerging patterns in the motions of the planets.
I'm a second year software engineering student at McGill University with a passion for math, science and learning. You can find more of my projects on my GitHub profile. I also have a small website that I don't maintain actively. This looks like the perfect opportunity to mention that I'm looking for an internship in software development and related fields for the summer of 2022. To learn more about my education and work experience or to contact me regarding this, please see my LinkedIn profile.
Yes. I'm not sure what use this could have to others, but to make sure this doesn't get forgotten in a corner of my hard drive if it is useful to anyone else, this website, its source code, and all its content is licensed under a CC-BY Creative Commons Attribution 4.0 International License.
[1] As of , to the best of my knowledge. Note that there are solutions for the specific case of n = 2 and to a restricted version of the 3-body problem. Relevant Wikipedia article. ↩