Interactive N-Body Gravitational Simulator (3-Body Focus)

A real-time Python simulation of gravitational systems using Euler-Cromer integration, built to explore the chaos and beauty of N-body dynamics.

Created

April 1, 2025

Last Updated

August 1, 2025

Duration

6 Weeks

Overview

This project is an interactive Python simulation of the N-body gravitational problem, with a specific focus on the 3-body system. It uses the Euler-Cromer integration method to numerically evolve the system and visualize particle trajectories in real time. The code is designed to be extensible, allowing future support for larger particle systems and alternative integration methods (e.g., Runge-Kutta or symplectic schemes). Emphasis is placed on exploring nonlinear dynamics, conservation of energy, and system stability. The GUI uses Matplotlib's animation and widget features for user control, making the simulation both educational and interactive.

Key Features

  • Euler-Cromer numerical integration
  • Interactive particle reset and playback controls
  • Real-time trajectory visualization with custom styling
  • Softened gravity for improved numerical stability
  • Energy conservation tracking (planned feature)
  • Customizable initial conditions and extensible particle setup

Example Code

Demo Video

Technical Implementation

This N-body physics simulation explores the fascinating dynamics of gravitational systems, particularly focusing on the classic three-body problem. The implementation uses the Euler-Cromer integration method, which provides a good balance between computational efficiency and numerical stability for orbital mechanics simulations.

Integration Method

The Euler-Cromer method (also known as the semi-implicit Euler method) is particularly well-suited for this type of simulation because it conserves energy better than the standard Euler method. The algorithm updates velocities first using the current positions, then updates positions using the new velocities.

Parameter Control

Users can adjust various simulation parameters including:

  • Initial positions and velocities of celestial bodies
  • Mass ratios between different objects
  • Integration time step for accuracy vs. performance trade-offs
  • Simulation duration and output frequency

Future Enhancements

  • * Implementation of higher-order integration methods (e.g. Runge-Kutta 4th order)
  • * Interactive GUI for real-time parameter adjustment
  • * Energy conservation analysis and error tracking
  • * Extension to N-body systems with arbitrary number of objects

Project Information

Details

Category: code
Status: completed
Duration: 6 Weeks

Technologies

Python NumPy Matplotlib

Tags

#physics #simulation #numerical-methods
Licensed under CC BY-SA 4.0 • Free to share and adapt with attribution
Citation formats
"Interactive N-Body Gravitational Simulator (3-Body Focus)" by Jacob Poore, April 1, 2025. Available at: https://jacobpoore.wescreates.wesleyan.edu/projects/n-body. Licensed under CC BY-SA 4.0.
Poore, J. (2025). Interactive N-Body Gravitational Simulator (3-Body Focus). Retrieved from https://jacobpoore.wescreates.wesleyan.edu/projects/n-body
Poore, Jacob. "Interactive N-Body Gravitational Simulator (3-Body Focus)." April 1, 2025, https://jacobpoore.wescreates.wesleyan.edu/projects/n-body.