Tuesday, January 29, 2013

Programing the Heliocentric System in Python

Programming the Heliocentric System in Python

By Roy Stracovsky

To learn about the Scientific Revolution, I decided to recreate the current heliocentric system. With that in mind, I thought of how it should be made. At first, I thought that I could make it using a crude foam ball and wire system, but the planets couldn't move, and if I figured how to make them move, they would revolve around the sun in circles, and this is incorrect. I looked for other ideas, and thought about what I also wanted to learn, while learning about the heliocentric system, and it hit me, I should program the system. I decided to use Python, a language that is taught in the upper-school.

Before I go into how I programmed the system, I would like to explain when it was discovered. Previous to the system, there was a different system. This system was was the geocentric system and it displayed, that the sun and moon and planets revolve around the earth. This was created by Ptolemy.
As you can see, saturn, mars, jupiter, venus, and mercury, seem to be revolving in circles, around an invisible point, this is very odd, but back then, this was the way. In time, a scientist called Copernicus thought differently. He believed that all the planets revolved in a circular orbit around the sun. This is close to our current solar system, but this was slightly incorrect. He was missing the fact that planets revolve in ellipses. Later, Kepler, another scientist, discovered this fact through some data.

Now we can get to the program. First, we need to install Andrew Miller's Graphics Library to make the animations. Here is the webpage where you can download it.


Next we can make a new document in Python Idle. This is where we put our code.


Now we need to add the animation framework code. This is necessary for the library. It is the thing that runs the animation.


Next, we can make variables. The variables are only for mercury because I only want to test a olanet first, then add the others.


Now we need to define a function that takes a planets time it takes to orbit the sun, speed that it does that to, which place it is in in the system, and the size of the planet.
First you need to find the base size, and add it to increment of x times the orbit to the power of 1.1. Take all of this and divide it by two, and you have horizontal radius. To make the vertical radius, do the same but using the incrY instead.
To make the x position for the planet, add the horizontal radius to the cosine of the remainder of time multiplied by the speed, and 360. We will call this "degree".
For the y position, we take the radiusY, and multiply it by the sine of degree.
Now, we draw the circle, so when the function is applied, we want to make the circle. We put in the x coordinate and the y coordinate, and we put in the radius.
Now, for future planning, if the planet orbit is saturn, we want to add a ring on top of the planet.

Next, we add another function. This function draws the solar system. First, we draw a yellow circle, or the sun.
After that, we make a loop that starts at one and goes nine spaces, or to ten. We make a horizontal diameter that takes the base size and adds it to the product of incrX and the power of the time that is looped to the 1.1th. We do this to make the vertical diameter too. Now we draw an ellipse at the origin with the horizontal and vertical diameters.


Finally, we need to draw the things. We need to reset a matrix, make the origin in the center of the screen, draw the system in the current time, a variable that we create, and add one to the time.


Now for the final with mercury, you need to take away the orbit ellipse drawn, and fix up some bugs like the translate by adding 200.
Now you can add the other planets!




Nowadays, we take it for granted that the orbits are ellipses, but in reality, it is so hard to program and hard to discover. By doing this, this has been a quadruple learning situation through math, science, history, and computer science! I will forever have this seared in my brain.

5 comments:

  1. Thats so cool! I should try that sometime. Liked the video too. One question though, how long did this take to make?

    ReplyDelete
    Replies
    1. Hey Andrew,

      I recommend that you should do this, but maybe next year or as a freshman if you take the computer science course. Even I needed help with the math. This took two days as the 1.0, but I have made a new version with the real planet pictures, with a starry background, and I want to also make it so that you can see the info of each planet.

      ~Roy

      Delete
  2. Roy,
    I really enjoyed your post and video. It is so cool that you mixed your writing with a bunch of pictures. How did you know how to make the program, and what gave you the idea? You are very creative to use a computer program in a world cultures blog post. Nice post.
    -Isabel

    ReplyDelete
  3. Hi Roy,
    I liked your post, although it was a little confusing. I thought it was a very creative idea! How did you know how to program? I thought maybe you should explain what you were doing a little bit more. Also, planets might be proper nouns, and I would like it if you added a little more at the beginning. Your sentence about Kepler was very vague. Anyways, great job. I like how you put in the screen shots to help explain what you were doing.
    -Sarah D

    ReplyDelete
    Replies
    1. I mainly wanted to describe the change to the system instead of who and how they were found. This is great idea though and I would love to use this in future posts. It is also hard to explain because the math is beyond what we are doing in class, and python is one of the harder level languages. Also, my brother taught me how to over a _long_ period of time.

      Delete