Skip to content

GerFr/Python-Gravity-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Gravity-Simulation

This is an advanced orbital dynamics and n-body simulation program. Through simple rules of physics complex and beautiful behaviours can occur.

The main file is main.py wich has to be run to be started. SolarSystem.py and BarnesHut.py supplies the program with functions.

The Barnes hut algorythm is highly optimised for many bodies and makes larger scale n-body simulations possible.

Example runs can be found at YouTube.

Any help or assistance is greatly appreciated. Kindly share this project!

Planned features

  • clicking on objects

  • data handling with json

  • placing objects

  • ui package

please ask for features in discussions!

Installation guide

  1. download the code from github (either with .zip or git clone)

  2. install requirements.txt

This can be done with the command

py -m pip install -r requirements.txt

using cmd in the directory of the code.

A python installation is also needed. Version 3.10 or above peferred.

Running the code

Run the file main.py either from the file explorer, an IDE or CMD/shell.

Tweakables

There are easily exchangeable variables in the init function of the Interface class in the "UI with solar system.py". Possible options include a barnes hut overlay or random planet system generation rather than the solar system.

Sources

Gravity Physics

The Python Coding Book - Simulating a 3D Solar System In Python Using Matplotlib

Stack Exchange - Velocity verlet pseudo code

gereshes - Verlet Integration

Barnes Hut

Lewis Cole Blog - Barnes-Hut Algorithm

beltoforion - The Barnes-Hut Galaxy Simulator

OpenGenus - Octree data structure

Energy

Stack Exchange - Gravitational potential energy of an n-body

LibreTexts - Work and Kinetic Energy for a Many-Body System

UMD - The Virial Theorem

Collision

Plasmaphysics.org.uk - Elastic and Inelastic Collision in Three Dimensions