Saturday 20 December 2014

And here comes the whole Solar System! ;)

Modelling Sun, Earth and Moon only? Naah that’s too naive. Let’s add some other planets! Occhiolino
The code on my previous article was rather ugly. It did not follow an OOP style and it was mostly non re-usable. Aside from the content of the piece of code I posted in this article, I’m quite satisfied with how I set it: a class for planets and a class to handle time. Sure, perhaps this is not the smartest way of using a class, however for someone like me, who programs mainly as a hobby, that’s fine I guess.
This piece of code models and simulates the whole Solar System (without the Sun, you can add it though!) and gives you, aside from the code, a hint on how slow/fast planets are orbiting around the Sun. note that I use large intervals of time (10000 seconds or similar). This model for sure can be improved. For instance the colours could be improved and, jokes aside, perhaps elliptical orbits could be implemented instead of circular. To do that I still need to work on my knowledge of gravity and its implementation in Python.
solar sys

Anyway I’ll keep you posted. That’s it for now, here’s the code of the model and the YouTube video I made (but couldn’t load in the post, not sure why)

[EDIT]: I've finally made it and load the video here too! Enjoy



12 comments:

  1. Hi sir,
    how to install package 'visual' and 'bigfloat' on Windows10 and python 3?
    Thanks
    Graziano

    ReplyDelete
    Replies
    1. Hi Graziano, open a command prompt or a powershell prompt and type "pip install vpython" (without the quote marks). Then do the same with bigfloat. Bigfloat installation through pip might not work, if that is the case, you can download a .whl file of the package (to be installed by typing in the command prompt "pip install filename.whl") at this address: https://www.lfd.uci.edu/~gohlke/pythonlibs/

      Delete
  2. I got error in line 135 and 136.
    I could run this after modifying 'axis=(0,0,1)' to 'axis=vector(0,0,1)'.

    ReplyDelete
    Replies
    1. Additionally I used 'from vpython import *' instead of 'from visual import *'

      Delete
  3. but it is not elliptical. the circular is easy and wrong :)

    ReplyDelete
  4. Hi i got this: line 188, in rotate
    u = axis.hat
    AttributeError: 'tuple' object has no attribute 'hat'
    would you help me?

    ReplyDelete
  5. I'm doing a very similar project on python IDE as well, simulating the orbit of stars in our solar system around the sun. However, I am currently struggling to draw equipotential lines between the sun, and any star chosen orbiting the sun in the simulation. Any idea how I could do this? (I have the straight line equipotential line sorted, I just need 1 non linear equipotential line on both sides of that linear equipotential line)

    ReplyDelete
  6. hi, I seem to have problems downloading bigfloat and matplotlib.pyplot on vpython… it is the version 2.7 of python.
    thanks and keep it up your work is awesome!!

    ReplyDelete
  7. solar roof-top systems in Ahmedabad
    Vibrant Solar is a leading service provider of a Solar megawatt power plant and Solar roof-top systems in Ahmedabad, Gujarat with large corporate network of solar installation in rest of India.Our solar PV modules can withstand extreme climates, temperatures, humidity and pressure for over a 25-year period.

    ReplyDelete
  8. Huge thanks for this post! It was just what I was looking for!

    ReplyDelete