2D Orbital Simulator


This was my first real experience trying to make a somewhat thorough simulation, and I decided to do what I felt would be relatively simple and create a sort of ‘Universe Sandbox’ clone. The rules of gravity are pretty simple, and a meaningful and complex simulation can be made with relatively few parameters and some simple information about the simulated bodies.

A simulation of Mercury, Venus, Earth, and Mars orbiting the Sun (with scaling increased for visibility)

As can be seen above, the appearance of the simulation is very simple (especially given my limited experience with Processing and lack of artisticness). However, the simulation itself is relatively thorough, and each frame all of the bodies check the masses and relative positions of all of the other bodies to accurately determine a new force vector, and a new velocity and position vector accordingly.

Of course, it doesn’t work flawlessly. Things break down pretty quickly when the simulation speed goes too high, and adding orbiting bodies to moving bodies doesn’t work like it should either.

Planets fly away if the simulation speed is too high, likely because it can't process the frames fast enough

One unexpected part of this project was attempting to flesh it out into an entire application, with a navigatable menu system, settings, etc. While there certainly already exists some kind of library for organizing and displaying a menu UI, I was feeling a little crazy and opted to program my own Button and Menu classes. Was it fun? Kinda. Do I recommend it? By no means whatsoever, it looks pretty terrible and probably has minimal functionality compared to actually well-made and fleshed-out menu systems. Alas.

My poorly made (but not unusable by any means!) menu system

I also made the silly decision of making my own DateTime class, which especially with two years of hindsight I can see was pretty ridiculous. A good exercise though!

If I were to do this again (which I’ve recently been feeling a little inclined to do), I’d probably re-write it in C++ (sooo fast!) and try to do it properly. I’d like to implement orbit trails, predictive orbits (draw a little trail indicating where a body to-be-placed will go), etc.

Automatic VitalCheck ⇢