The odd bit

Once is an accident, twice is a coincidence, three times is an enemy action.

The odd bit - Once is an accident, twice is a coincidence, three times is an enemy action.

Simulate a solar system

I’ve picked up OpenGL programming once again and this time I’m going to try to simulate our solar system. That sounds very simple, but it’s actually quite complex when you start researching for the necessary data. It’s supposed to be a simulation so wild guesses are a big no-no. The only trade-offs I’m willing to make are (1) all planets are perfect spheres and (2) all orbits are perfect circles. And in a later phase, I’d let to get rid of the latter limitation.
I decided to put all data I might need in a spreadsheet and then started recalculating all stuff to use units that I could use in the OpenGL environment, namely pixels and seconds. This again sounds very simple until you actually see the results.

The size of the spheres and the distance from the centre (the Sun) are scaled. This gives the Sun a radius of about 109 pixels, while Pluto ends up with a radius of about 0.18 pixel. You might say “make them all bigger” but that would have consequences for the distance from the Sun as well. The planet closest to the Sun, Mercury, would have an orbit with a radius of about 9000 pixels while the has a radius of 0.38 pixel. Starting to see the problem? Pluto, the outermost planet, has an orbit with a radius of 926000 pixels. Doubling the size of the spheres would double those distances too!

Just to fit the whole solar system in the application, I would need 1.9 million pixels on the Z-axis. The net result: you wouldn’t see anything on your screen.

The same problem surfaces when you recalculate the times. The event that takes the most time is a complete orbit (or revolution) of Pluto: nearly 248 earth years. You obviously can’t wait that long to see one lap of Pluto 😉 But that event was my starting point of the calculations. I started from the idea that one lap around the Sun should take 600 seconds (or 10 minutes) for Pluto. Here we go…

One earth year would then take a whopping 2.42 seconds, which still sounds quite reasonable to me. The Earth would complete one lap around the Sun in nearly 2 and a half second. One earth day would take 0.0066s. In other words, one rotation around its axis would take the Earth 6.6 milliseconds. You might see a bit of flickering if it’s textured, but otherwise it would go unnoticed. Our lovely Mercury, which is the fastest planet when it comes to orbital speed, would revolve around the Sun in 0.58s. Still too fast…

One problem is size vs distance and the other problem is revolution vs rotation. If anyone knows of a good solution without decoupling the relationship (size-distance is of course decoupled from rev.-rot.) within one problem, please let me know :-)