Tuesday, February 4, 2014

Solar System

The purpose of this project was to create a force registry system for rigidbody movement that registers force generators with bodies and then applies them for a desired rotation; I then used this force registry system to create a very basic planetary motion simulation using to-scale units so that the bodies (the sun, the moon, and the eight planets) at least started at to-scale distances away from their orbital center and the correct velocity and had to-scale radii and masses and all apply gravity to one another based on these traits. Once I got the force registry system working and tested using arbitrary values which was pretty straightforward, the next biggest challenge was determining which units to use consistently across the board so that the gravitational constant (G = 6.67384e-11 m^3/kgs^2) could be scaled appropriately; I used WolframAlpha to determine these traits of the planets, sun, and moon in whatever units it returned and then compared a couple different unit options to find one that yielded semi-people-friendly numbers across the board:
These numbers were ultimately stored in doubles so as to have as few worries about loss of significant digits in multiplication as possible. The chosen units are the darkened columns: megameters for distance and yottagrams for mass; this yielded a gravitational constant of G = 6.67384e-8 Mm^3/Ygs^2. In the simulation, to speed it up so that it wasn't moving in real time and imperceptibly slowly, I set the timestep per frame to represent about 5500 seconds, which worked well for the inner planets and bumped it up to 400,000 seconds for viewing the outer planets motion; unfortunately toggling this timestep change completely throws off the inner planets.

This shows the simulation running, starting with just visibility of the inner planets in relatively stable orbits, zooming out a bit to start to see the outer planets and then switching to a preset zoom that I found was ideal for viewing the outer planets' orbits, then the time step is increased right at the end (apologies ahead of time for video quality):

You might notice that the size of the planets do not change as it is zooming out and then the inner planets become much smaller when it is switched to the "outer planet view"; this is because if the planets were left displaying to-scale, most of them would show up on-screen as maybe a pixel every once and a while; to prevent this, I implemented a toggleable function that allows you to calculate the "screen radius" of the planet and set a minimum proportion they could appear as so that they would scale if they showed up as below a certain proportion of their respective radii. For better visibility in the outer planet view, that proportion decreases for the inner planets while in this view or while viewing outer planets up-close as will be shown later. This shows this minimum size functionality:
As you can see, all of the bodies are reduced to rendering just the occasional pixel aside from the sun which stays somewhat visible in the inner-planet view mode.

Unfortunately, with the addition of this minimum scale, the earth "eats" the moon in all the system views, but I assure you: the moon is, in fact, orbiting the earth at the same time as everything else. This demonstrates the earth being targeted as the video anchor point and you can see as the earth is zoomed in on, the moon is maintaining an orbit:

The camera also has a pretty full range of motion and rotation and each planet can be selected as a more "perspective" viewpoint base that will also display the current trait information about that planet which is fun to watch as the system and orbits gradually become unstable. This first video demonstrates this targeting of each of the planetary bodies and the second one demonstrates "looking around" from the earth viewpoint.