Learning the Steps to the Orbital Dance

Showing a Visualization of the Orbits of the Inner Planets

Rafael Ferreira
The Startup
5 min readFeb 24, 2021

--

Actual orbits of our solar system, sped up to show the difference in orbits in terms of time.

When it comes to properly visualizing our solar system, astrophysicist realize there are many interactions among the different planets that affect the orbit of each body. When simulating just one body and its path, there are many interactions that go along with figuring out its trajectory.

In order to display the actual orbits of the planets, we must first bring this matter to simple mechanics. Newton discovered three distinct laws that govern our universe, with the second law being the one of importance for our simulation. The second law states that an object with mass m, and an acceleration a has a resulting force.

The above equation also shows that an object of mass m, with any given force F, that will produce some resulting acceleration a . In this simulation we want to calculate the acting acceleration given by all acting bodies. The equation for acceleration of a single body, i, in a three coordinate system is in the x direction is:

acting acceleration in the x direction given by multiple bodies.

The equation takes into account, G, the gravitational constant, m the mass of thee body, and the location of the body in the coordinate system of x, y, and z. Summing all values over all coordinates to get the resulting acceleration in one direction. In order to determine the y and z directional accelerations you change (xⱼ- x) to the dimension you want to calculate in. Now if we are given the bodies velocity and its position then by taking the derivative we are able to calculate the bodies acceleration.

  • m = mass of the object
  • rᵢ = [xᵢ, yᵢ, zᵢ] position of the object
  • vᵢ = [vxᵢ, vyᵢ, vz] the velocity of the body in all three coordinates

Now we can start creating our classes and proper functions to create the simulation. First we need to import our packages needed to plot and create our classes.

The first class we create is the point class that initializes the object state in all three coordinates, in which we will provide when we set up the body we want to simulate. Now, we need to set up the body class where we feed in the location, mass, velocity, and name of that body. Once we have these classes setup we can calculate the acceleration of a single body due to the forces acting on that object from external forces.

We first start with the gravitational constant , G, where that is the force felt between two bodies, and it is a weak force at that. This is why, in order to feel a strong resulting force, our objects need to have very large masses, in the order of billions of kgs. Then we initialize the acceleration to be zero, which then will be updated as we calculate the acceleration at various points in the orbit of the object. We then need to specify what our target body is when we calculate its acceleration based on the affect of the other objects. Next we need to grab the key, value pair for each target object and calculate its location and acceleration at that location based on its mass and velocity. Once we have the location of the object we can input this location into Kepler’s Third Law, T = Gm/ r³. Using this information we can then determine the orbit of our target body. Next, we find the acceleration in each coordinate system, then summing them up to one acceleration which will then used to update the previous orbit. As the target object moves throughout its orbit its velocity changes relative to the other objects gravitational affects on the target body.

Having calculated the initial orbits of each of the bodies in the system we again reiterate through each body to update their orbits at each different location. We use the previously calculated acceleration to update their velocity in each coordinate system overtime. With our velocity of each object now updated, we then can update the location of the object within its orbit of the given body based on the new velocity.

We now iterate again for a third time to adjust for the new velocities. Then we can put these two functions together to refine the orbit at each gravitational step.

Now for the fun part. Once all are pieces are together, we can simulate our bodies or objects around a single point mass, in this case the Sun.

The first part of running our simulation is creating an empty list of the historical locations of each body in order to plot. Then we iterate through each body to update its locational history every time a new gravitational step occurs. We chose the size of the steps which will determine the new location and velocity. We then confirm that the gravitational step is an even number to check if we have an elliptical orbit.

Our final step, plotting the bodies. In this example, we will plot the Sun with Mercury, Venus, Earth, and Mars aka all the terrestrial planets.

We first take in two parameters, all of are chosen planets, and whether or not we want to save the plot. We then create our figure, designate each planets to a color for differentiation of planets, and output the max dimension of each of the planets based on the gravitational step size we choose. Then plot!

Time Step equal to a 1000, number of steps equal to 100,000, and report frequency of 1000.
Time Step equal to a 1000, number of steps equal to 10,000, and report frequency of 1000.

Each visual shows the difference of the orbits of all 4 planets at different gravitational step orbiting the Sun. The Sun is not displayed as the orbits are relative to the Sun, with the Sun being the center of our solar system. This is how you show the orbits of the planets or any given object using its mass, velocity, and location.

Side note: Shout out to Ben Eagen for showing this tutorial, and creating passion among many python programmers.

--

--

Rafael Ferreira
The Startup

Undergraduate in Physics concentration in Astrophysics. Thesis in classification of Eight Young Stellar Objects in the SMC. Data Science Bootcamp Flatiron