STARS GUI
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.
Table of Contents
About The Project
The Implementation
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.
Built With
Getting Started
Installation
-
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 Parameters:
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: str
name: 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
The Equations:
According to Newton's law, for a set of $n$ celestial objects, we have the force applied to the $i$-th object given by:
$$F_i = - Gm_i \sum_{j=1, j\neq i}^n \frac{m_j}{r^2}\vec{u_{ij}}$$
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 $i$, we compute its acceleration at time-step $t$, which is simply:
$$a_i(t) = F_i(t) / m_i$$
Then, using Euler's resolution method, we have:
$$dv_i(t) = a_i(t) \cdot dt$$
$$dx_i(t) = dv_i(t) \cdot dt$$
Hence, we can compute the new velocity, the one at time $t+dt$:
$$v_i(t + dt) := v_i(t) + dv_i(t)$$
And the new position:
$$x_i(t + dt) := x_i(t) + dx_i(t)$$
Notice that the computation have been made not considering the type of the referential. In the program, everything are compute in an euclidian one.
Run The Animation:
Just run:
Usage
After 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.
Roadmap
- Make interactive GUI
- Select manually different options
- Live simulation
- Change equations
- Black Holes
Contributing
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
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Arthur Testard - testardarthur@gmail.com
Project Link: https://github.com/art-test-stack/stars_gui