Modelling Sun, Earth and Moon only? Naah that’s too naive. Let’s add some other planets!
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.
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
Hi sir,
ReplyDeletehow to install package 'visual' and 'bigfloat' on Windows10 and python 3?
Thanks
Graziano
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/
DeleteI got error in line 135 and 136.
ReplyDeleteI could run this after modifying 'axis=(0,0,1)' to 'axis=vector(0,0,1)'.
Additionally I used 'from vpython import *' instead of 'from visual import *'
DeleteCOOL
ReplyDeletebut it is not elliptical. the circular is easy and wrong :)
ReplyDeleteHi i got this: line 188, in rotate
ReplyDeleteu = axis.hat
AttributeError: 'tuple' object has no attribute 'hat'
would you help me?
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)
ReplyDeletehi, I seem to have problems downloading bigfloat and matplotlib.pyplot on vpython… it is the version 2.7 of python.
ReplyDeletethanks and keep it up your work is awesome!!
solar roof-top systems in Ahmedabad
ReplyDeleteVibrant 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.
solar resco model
ReplyDeletesolar panel manufacturing company in india
Huge thanks for this post! It was just what I was looking for!
ReplyDelete