Introduction: Solar System Simulation

About: I am a junior in college and a part-time maker.

For this project I set out to create a simulation of how gravity affects the motion of planetary bodies in a solar system. In the video above\, the Sun body is represented by the wire mesh sphere, and the planets are randomly generated.

The motion of the planets are based on real physics, the Law of Universal Gravitation. This law defines the gravitational force exerted on a mass by another mass; in this case the Sun on all the planets, an the planets on each other.

For this project I used Processing, a java based programming environment. I also used the Processing example file that simulates gravity of planets. All you will need for this is the Processing software and a computer.

Step 1: 2 Dimensional Simulation

I began by watching some videos on how to go about coding this that Dan Shiffman created on his YouTube Channel, the Coding Train ( Part 1/3). At this point I thought that I would use recursion to generate the solar system, similar to how Shiffman does only using the laws of physics.

I created a planet object that had 'children planets', who in turn also had 'child' planets. The code for the 2D simulation wasn't finished because I didn't have a great way to simulate the gravitational forces for each planet. I pivoted from this way of thinking, in a direction based on the in-built processing example of gravitational attraction. The issue was that I needed to calculate the gravitational force from all the other planets on each planet, but couldn't think of how to pull the information of an individual planet easily. After seeing how the Processing tutorial does it, I realized exactly how to do it using loops and arrays instead

Step 2: Taking It to 3 Dimensions

Using the example code for Planetary Attraction that comes with processing, I started a new program for a 3D simulation. The major difference is in the Planet class, where I added an attraction function, that calculates the gravitational force between two planets. This allowed me to simulate how our solar systems works, where the planets are not just attracted to the sun, but also to every other planet.

Each planet has randomly generated characteristics such as the mass, radius, initial orbital velocity, etc.. The planets are solid spheres ans the Sun is a wire-mesh sphere. Additionally, the camera location rotates around the center of the window.

Step 3: Using Real Planets

After I got the framework for the 3D simulation down, I used Wikipedia to find the actual planetary data for our solar system. I created an array of planet objects, and input the real data. When I did this, I had to scale down all of the characteristics. When I did this I should have taken the actual values and multiplied by a factor to scale down the values, instead I did it in units of Earths. That is I took the ratio Earth's value to the other objects' value, for example the Sun has 109 times more mass that the Earth. However this resulted in the sizes of the planets looking too large or too small.

Step 4: Final Thoughts and Comments

If I were to continue working on this simulation I would refine/improve a couple of things:

1. First I would scale everything uniformly using the same scaling factor. Then to improve the visibility of the orbits, I would add a trail behind each planet to see how each revolution compares to the previous one

2. The camera is not interactive, which means that part of the orbits are off the screen, "behind the person" viewing. There is a 3D camera library called Peazy Cam, that is used on Part 2 of the Coding Train's video series on this topic. This library allows the viewer to rotate, pan, and zoom the camera so that they would be able to follow the entire orbit of a planet.

3. Finally, the planets are currently indistinguishable from each other. I would like to add 'skins' to each planet and the Sun, so that viewers can recognize Earth and such.