This project has to purpose to create an animation of celestial bodies and they gravitational interactions, according to Newton's law and Euler's resolution.
This project permits to easily see how the different bodies in a set of celestial bodies, for example the solar system, how they influence the others and how they are influenced by them. So, anyone who want to see, for example, how the solar system runs, or any other set of celestial bodies does, can use it as a first step to see how a little piece of our universe can work !
However, it is only good as a first step, the equations used here are very basic, even if they handdle a big variety of situations.
Explore the docs »
Request Feature
Table of Contents
This project easily implement a resolution of Newton's gravitational law equation using Euler's method for a problem. For a defined number of celestial objects, the program compute the trajectory and provide a playful representation. The program also copute all the interactions between the different stars.
It can handles different objects called CelestialBody in the code, with different positions from the middle, velocity, masses etc... All of the details are bellow in Parameters part.
-
Clone the repo
git clone git@github.com:art-test-stack/stars_gui.git
-
Create a virtual environment
For example I use virtualenv:
virtualenv -p python 3.10 venv
-
Install pip packages
pip install -r requirements.txt
The different basic parameters can be found on constants.py.
from dataclasses import dataclass
from typing import List
@dataclass
class CelestialBodyBase:
name: str
r_i : float
v_i : List[float]
mass: float
color: strname: the name of the celestial bodyr_i: the distance to the middle of the canva (the biggest body is placed their). The angle is randomly set up on the circle defined by the middle and the radius.v_i: the absolute velocity of the celestial bodymass: the mass of the celestial objectcolor: the color of the celestial object
According to Newton's law, for a set of
where,
-
$G$ : is the universal gravitational constant -
$m_i$ : is the mass of the$i$ -th object -
$r$ : is the distance between the two objects$j$ and$i$ -
$\vec{u_{ij}}$ : is the unitar vector from$i$ to$j$
Then for evey object
Then, using Euler's resolution method, we have:
Hence, we can compute the new velocity, the one at time
And the new position:
Notice that the computation have been made not considering the type of the referential. In the program, everything are compute in an euclidian one.
Just run:
python main.pyAfter having followed every part above, python should open a window looking live the one bellow.
You can add some objects by giving them some particularities. By default, when you start simulation, it runs with all the planetaries of the solar system, plus the sun and the objects you added.
- Make interactive GUI
- Select manually different options
- Live simulation
- Change equations
- Black Holes
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Arthur Testard - testardarthur@gmail.com
Project Link: https://github.com/art-test-stack/stars_gui