I’m making a small project every day in python for the next 30 days (minus some vacation days). I’m hoping to learn many new packages and make a wide variety of projects, including games, computer tools, machine learning, and maybe some science. It should be a good variety and I think it will be a lot of fun.
Day 10: An Orrery
An orrery is a device for demonstrating the motion of the planets in the solar system. Typically it was made with gears but mine is with python code. Specifically, I used the Vpython package which is a great tool for visualizing physics because it uses the
numpy package for the numerical backend and allows you to manipulate the graphics with ordinary math coordinates instead of computer screen coordinates. This means you can write a physics equation and get the resulting motion out very easily. The inspiration for this project and the other science simulations that I’m planning is Rhett Allain’s blog over at Wired. I love the simulations that he puts together to answer scientific questions.
It’s impossible to show everything in the the solar system within a single scale since it is so big. Instead, I use two scales: astronomical units for distance from the sun and earth radii for radii of the planet. I can then balance the ability to see the planets and the ability to see their orbits. The Sun’s radius is in astronomical units so it won’t dominate the visual (it’s 100 times bigger than Earth). Here’s a snapshot of the 6 classical planets travelling around the sun:
I can turn on and off planets with a control list to get more or less detail. Here’s the view that includes Pluto:
Because this is computer code, it’s very easy to change the frame of reference. Instead of looking at the solar system with the sun in the center, you can see how the planets move “around” the earth (or any other planet). Looking at the shape of the orbits from other reference frames gives you a sense of what the Greek model of epicycles would have been like. Epicycles are a method of describing planetary motion using nested rotating shells within shells that create the complex motions observed from earth. Each planet gets several epicycles to account for getting closer and further from Earth at various times. It’s a very complex model to account for all of the motion. Plus, they are fun to watch:
Writing out an explicit equation for these complex motions would be nearly impossible, but since everything is relative in the code it’s quite easy:
- Calculate Earth’s position (fixed)
- Calculate Sun’s position (circular to Earth)
- Calculate third body (circular to the Sun)
No need to solve for Jupiter relative to Earth or anything like that. Here’s what an geoentric model and Jovian (Jupiter) centric model look like:
I love the way that the inner planets dive towards the sun as they “orbit” around Jupiter. Each one of the loops would be explained away as part of an epicycle around the larger cycle that went around the Earth. My model is not an exact representation of the solar system though so you would need fewer (probably two) epicycles to build a truly earth centric model. To truly account for all the variation the Greeks saw, they had to include a lot more epicycles than just the two that show up here. Their system actually provided accurate calculations for a long time; it took a thousand years for the planetary positions to be noticeably off the predictions.
Science is about figuring out how reality works (or at least how it tends to work). To that end we build models through sets of equations, tables of properties, or some simulation code. In the end, we hopefully get a better model than we had before, but it it may never be perfect. Some limitations in my model:
- It models motion not force (this is a clock work universe)
- It assumes circular motion (see how off Pluto is?, this is Copernicus style not Kepler style)
- It assumes a flat solar system (Pluto would be off the plane)
There are a few things that I think I could add:
- Add rotation to show days
- More moons!
- Maybe a comet or two
- How about some asteroids?
For those that are interested, here’s my new science simulations repository: https://github.com/robb07/science_sims