Solar System

How it Works

Firstly, to keep track of all of the changing values in the solar system, we need to simplify it into as few variables as possible. To keep this explanation simple, we will just focus on Earth, and ignore the other planets for now. With that in mind, we come out with a variable list that looks like this:

(It should be noted that VX and VY stand for Velocity X and Velocity Y.)

That's a rather large number of variables to deal with, but we're in luck: some of the variables are constant. The Earth's mass isn't going to change much during the simulation, so we can afford to give it a set value at the beginning of the program, and ignore changing it in the future. The same goes for the Gravitational constant, the Sun's radius, and the Sun's mass. Because the sun is in the center of the solar system, its position won't change much, so SunX and SunY can both have a constant value of 0, putting the sun in the center. With this in mind, we can narrow our list down to this:

Now that our list is shortened, we can set the values in the simulation to average values for the Earth to begin the simulation. Keep in mind that all of these variables will change during the simulation.

\(Earth_{x} = 1.496 \times 10^{11} \mathrm{m}\)

\(Earth_{y} = 0 \mathrm{m}\)

\(EarthV_{x} = 0 \mathrm{m/s^2}\)

\(EarthV_{y} = 3.0 \times 10^{4}\left.\mathrm{m}\middle/\mathrm{s}^2\right.\)

Now that we have the positions of both the Earth and the Sun, we can calculate the gravitational force that the Sun has on Earth in Newtons. We are able to calculate Distance using the Pythagorean Theorem, so the only unknown variable would be the total force on the Earth. The equation for force is the following:

\(TotalEarthForce = GravitationalConstant \times \frac{SunMass \times EarthMass}{distance^2}\)

We now know the total force of the sun on Earth, but we need to calculate the horizontal and vertical force on the Earth, as the total force is not helpful. As an example of calculating this, a planet at the position (3, 4) would have 80% of the total force be applied to the vertical force, because the vertical distance from the sun (at point(0, 0)) is 80% of the total distance. Basically, we are making the Earth move directly toward the Sun, because that's how gravity acts. We can now apply this proportional reasoning to the total force on Earth in order to devise these formulas:

\(EarthForce_{y} = TotalEarthForce \times \frac{SunY - Earth_{y}}{distance}\)

\(EarthForce_{x} = TotalEarthForce \times \frac{SunX - Earth_{x}}{distance}\)

Alright, we are now making significant progress. Now that we have the Earth's directional forces (conveniently, this formula also works for negative y and x values for Earth in addition to positive values!), we will set the Earth's acceleration by them like so:

\(EarthAcceleration_{x} = \frac{EarthForce_{x}}{EarthMass}\)

\(EarthAcceleration_{y} = \frac{EarthForce_{y}}{EarthMass}\)

The above conclusions are based on Newton's second law of motion: F = MA. That is,

\(Force = Mass \times Acceleration\)

Knowing the force and Mass on the Earth, we can find out the Earth's acceleration algebraically. We just have to state that A = F / M, as it is the same statement as F = M * A. The force on Earth is the same as the force on the Sun. Because of this, we can conclude that the Earth's Mass * Earth's Acceleration is equal to the Sun's Mass * the Sun's acceleration. Because the Sun's mass is about 330,000 times that of the Earth, it's acceleration is extremely small, meaning it barely moves. As a result of this, we do not need to calculate the Sun's motion, as it is extremely slow, and would be unnoticeable in the simulation.

Of course, we need to change the velocity of Earth, otherwise it will fly out of orbit. In order to do that, we just add the acceleration to the velocity, but the acceleration is first multiplied by the time interval that passed (a constant variable). With that, we produce:

\(EarthV_{x} = EarthV_{x} + EarthAcceleration_{x} \times TimeInt\)

\(EarthV_{y} = EarthV_{y} + EarthAcceleration_{y} \times TimeInt\)

And here's the final part: we update the Earth's position. To do that, we add the velocities to Earth's current x and y position to complete the entire orbit. We simply have to state:

\(Earth_{x} = Earth_{x} + EarthV_{x}\)

\(Earth_{y} = Earth_{y} + EarthV_{y}\)

...and we're done! We have successfully moved the Earth from one point in time to the next point in time in the simulation. Of course, moving the Earth once isn't impressive. More work has been done, mainly placing all of the above formulas into a loop that repeatedly updates the Earth's position based on the updated Force, which is based on the previous updated position, and so on. Other than that, drawing the planets and the Sun, and translating the formulas into Javascript, the entire simulation is complete, and works great! Hope you found this walk-through useful!

- Arthur Z