# Understanding the Universe through Code: Planetary Motion

We know that our planet Earth is in constant motion around the Sun.

Have you ever thought about how our ancestors discovered this?

I think most of us don’t fully appreciate the difficulties that they encountered in making this discovery.

Even though we are not feeling it, the Earth is actually moving around the Sun at a staggering speed of 30km/s.

Just go out and look at the sky during the day time or at night and see if you can find any hints that will help you to reach this conclusion. It turns out that there aren’t any trivial ones.

It took the effort of a lot of great scientific minds, over several years, to discover this.

In this article, we are going to make an effort to understand and appreciate the beauty of this discovery with the help of visualizations.

Before that, let me tell you about one of the most important observations made by our ancestors that lead to this discovery.

They carefully observed the motion of planets in the sky over several days and months and kept track of their positions very accurately.

They found out that the planets traced out a curve which looked like this.

Can you believe that this observation was what lead them to speculate (correctly) that the Earth and the other planets are moving around the Sun?

How on earth did this “curve” that they observed in the sky lead them to this seemingly unrelated conclusion?

Let us try to find this out by creating a miniature solar system visualization.

And with the help of a few lines of code, we make our solar system model.

There is Earth, Mars and the Sun.

Now let us shift the centre of the coordinate to the Earth. This is necessary because from our viewpoint, we feel that the Earth is stationary and the rest of the heavenly bodies are moving around us.

Now from this viewpoint, let us look at the trajectory traced by Mars.

At first, it might look confusing, but observe this visualization for some time.

Does the curve look familiar?

The curve that we see in the sky is a small portion of the curve that we obtained now. But it looks squeezed when viewed from Earth’s vantage point.

We obtained this by shifting the centre of the coordinate system to the Earth and tracing the path of Mars. Cool isn’t it?

It took Johannes Kepler almost 40 years to analyse the data of the positions of the planets to finally come up with his laws that mathematically explained these ideas.

If you wish to get more clarity into these ideas, please see the workbook given below and play around with the visualizations and code yourself.

Workbook (Open in desktop)

PS – While creating the visualizations, I’ve assumed that the orbits of the planets are circular. But in reality they are elliptical. The circular orbit which is an approximation gives us a reasonably good explanation. But to be more precise, we need elliptical orbits.