Skip to content

About

Newtonian N-body Physics Simulator on Python with Barnes-Hut

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

63 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Icarus — N-Body Gravity Simulation

A Python/Pygame simulation implementing Newtonian gravity with Barnes-Hut optimization for efficient N-body force calculation.

The simulation visualizes the interactions between multiple bodies using gravitational attraction, while additionally supporting collisions, merging, camera movement, and randomly generated orbital systems.

More detailed information about the project and its technicalities is provided in the report: Project Report

Features

  • Barnes-Hut quadtree optimization
  • Newtonian gravitational physics
  • Elastic collisions with optional simple positioning fixing
  • Optional anchoring and body merging
  • Random orbital system generation
  • Camera movement
  • Real-time FPS, body count and node count metrics
  • Support for 1000 bodies with optimized settings

Screenshots

Orbital system with 1000 bodies, early stage

Early stage orbital system

Late stage orbital system with 1000 bodies

Late stage orbital system

Barnes-Hut quadtree visualization

Barnes-Hut quadtree

Performance testing data

Performance testing data was collected on an Apple M4 Max Mac Studio, using the standard orbital system configuration.

The graph compares the performance with and without the Barnes-Hut optimization to see the effect of the algorithm on simulation performance.

(The Barnes-Hut configuration used:

  • BARNES_HUT_THETA = 0.5
  • SKIP_REBUILD_STEPS = 1)

The y-axis represents the average FPS, the x-axis represents the number of random bodies being simulated.

(PERFORMANCE OF THE SIMULATION MAY VARY ON DIFFERENT HARDWARE, SOFTWARE AND WITH DIFFERENT SIMULATION SETTINGS)

Performance graph

Installation instructions

(Requires Python 3.x.)

Clone the repository:

git clone <repository-url>
cd <repository-name>

Install dependencies:

pip install -r requirements.txt

Run the simulation:

python main.py

Controls

Key Action
W Move camera up
A Move camera left
S Move camera down
D Move camera right

Author

Dmitry Wilder

Created as a personal project to learn, investigate and explore physics simulation, quadtree systems, optimization techniques and real-time visualization in Python using Pygame.

About

Newtonian N-body Physics Simulator on Python with Barnes-Hut

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages