https://github.com/robertapplin/n-body-simulations
A QWidget used for simulating a gravitational system of N bodies in two dimensions.
https://github.com/robertapplin/n-body-simulations
cplusplus n-body-problem n-body-simulator python qt-widget
Last synced: about 2 months ago
JSON representation
A QWidget used for simulating a gravitational system of N bodies in two dimensions.
- Host: GitHub
- URL: https://github.com/robertapplin/n-body-simulations
- Owner: robertapplin
- License: mit
- Created: 2020-09-27T14:32:54.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-08-20T19:58:41.000Z (almost 3 years ago)
- Last Synced: 2025-08-25T18:48:23.633Z (10 months ago)
- Topics: cplusplus, n-body-problem, n-body-simulator, python, qt-widget
- Language: Python
- Homepage:
- Size: 682 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# N-Body Simulator


[](https://coveralls.io/github/robertapplin/N-Body-Simulations?branch=main)
This project creates a QWidget used for simulating a gravitational system of N bodies in two dimensions.
## Table of contents
* [Installation](#installation)
* [Usage](#usage)
* [About](#about)
* [Features](#features)
## Installation
This widget was created using **Python v3.8**, and using **CMake v3.12**. These versions are a minimum requirement. It is also recommended that you create a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) and activate it before starting the installation process.
The first step is to clone the code in this repository using [git](https://git-scm.com/downloads):
```sh
git clone git@github.com:robertapplin/N-Body-Simulations.git
```
Then install the python environment requirements and Qt dependencies using pip:
```sh
pip install -r requirements.txt
```
Next, from within the project source directory, build and install the project. If this command fails, try running it as admin.
```sh
python setup.py install
```
The n-body-simulations package can now be found in the site-packages of your virtual environment.
## Building Locally
You can also build the code locally from git bash, from your source directory and with your virtual environment activated. Pass the following
flags to the first cmake command below: ``-DPYTHON_EXECUTABLE``, ``Dpybind11_DIR``, ``DCMAKE_INSTALL_PREFIX``, ``DCMAKE_INSTALL_LIBDIR``
```sh
cmake --preset=vs-debug .
cmake --build ../build
```
## Usage
From python, you can now import and open the widget as follows:
```py
from n_body_simulations.startup import startup_widget
startup_widget()
```
It is also possible to embed the widget into an existing interface.
## About
The purpose of this project was to develop my programming skills by creating a maintainable and well-tested cross-platform application. In this project I have created a simulator for N-Body gravitational systems which allows the collision and merging of bodies. The **docs** folder contains example \**.txt* files which can be loaded into this widget.
The following units have been used for this project:
|Quantity |Measured in |Unit|
|----------|--------------------------|----|
|Mass |Solar masses |M* |
|Position |Astronomical units |au |
|Time |Days |d |
|Velocity |Astronomical units per day|au/d|
## Features
The widget has several options which are found above the data table:
|Button |Description |
|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
|
|Load a \**.txt* file containing initial parameters for an N-Body-Simulation. |
|
|Save the initial parameters of an N-Body-Simulation to a \**.txt* file. |
|
|Remove the selected bodies from the simulation. |
|
|Add bodies to the simulation. |
|
|Adjust the time step and duration of the simulation. |
|
|Show or hide position labels and velocity arrows on the plot. |
|
|Turn on interactive mode, allowing you to interact with the bodies on the plot.|
|
|Stop the simulation. |
|
|Play or Pause the simulation. |
The widget also includes an interactive plot where you can:
|Image |Description |
|----------------------------------------------------------------------|-------------------------------------------------------------------------------------|
|
|Adjust the colour and name used to represent a body. |
|
|Adjust the position of a body by dragging the body on the interactive plot. |
|
|Adjust the velocity of a body by dragging the velocity arrow on the interactive plot.|