Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scorleos773/three-body-problem-simulator
Three-Body Problem Simulation - A Python-based simulation of the Three-Body Problem with both 2D and 3D visualizations. Uses `matplotlib` and `scipy` to model gravitational interactions and animate orbital trajectories. 🚀🔭
https://github.com/scorleos773/three-body-problem-simulator
differential-equations matplotlib mplot3d newtonian-mechanics numerical-integration numpy orbital-mechanics python runge-kutta-methods scipy-integrate three-body-problem three-body-simulation
Last synced: 3 days ago
JSON representation
Three-Body Problem Simulation - A Python-based simulation of the Three-Body Problem with both 2D and 3D visualizations. Uses `matplotlib` and `scipy` to model gravitational interactions and animate orbital trajectories. 🚀🔭
- Host: GitHub
- URL: https://github.com/scorleos773/three-body-problem-simulator
- Owner: SCORLEOs773
- License: mit
- Created: 2025-02-11T11:08:23.000Z (3 days ago)
- Default Branch: main
- Last Pushed: 2025-02-11T11:39:39.000Z (3 days ago)
- Last Synced: 2025-02-11T12:25:24.252Z (3 days ago)
- Topics: differential-equations, matplotlib, mplot3d, newtonian-mechanics, numerical-integration, numpy, orbital-mechanics, python, runge-kutta-methods, scipy-integrate, three-body-problem, three-body-simulation
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Three-Body Problem Simulation
This repository contains Python implementations of the **Three-Body Problem**, a classical problem in celestial mechanics that involves predicting the motion of three bodies under mutual gravitational attraction. The simulations are available in both **2D** and **3D** versions.
## Features
- **2D Simulation**: Visualizes the orbits of three bodies in a 2D plane.
- **3D Simulation**: Adds depth and realism by simulating the bodies in three-dimensional space.
- **Custom Initial Conditions**: Modify mass, velocity, and starting positions for different scenarios.
- **Animated Trajectories**: Real-time visualization using `matplotlib.animation`.---
## 🛠 Installation
1. Clone this repository:
```sh
git clone https://github.com/yourusername/three-body-simulation.git
cd three-body-simulation2. Install the required dependencies:
```sh
pip install numpy matplotlib scipy3. Run the simulation:
a. 2D Version:
```sh
python three_body_2d.py
```
b. 3D Version:
```sh
python three_body_3d.py
---## 📜 How It Works
### Equations of Motion
The system is governed by Newton's law of universal gravitation:$$ F = \frac{G m_1 m_2}{r^2} $$
For each body, acceleration is computed as:
$$ a = \frac{F}{m} $$
Where G is the gravitational constant, 𝑚 is mass, and 𝑟 is the distance between bodies.
### Integration Method
The code uses scipy.integrate.solve_ivp with the RK45 method to numerically solve the system of differential equations.---
## 🎮 Usage
### Changing Initial Conditions
You can modify the starting positions and velocities of the bodies inside the Python files:```sh
initial_conditions = [
-1, 0, 0, 0, -0.5, 0, # Body 1
1, 0, 0, 0, 0.5, 0, # Body 2
0, 1, 0, 0.5, -0.5, 0 # Body 3
]
masses = [1, 1.5, 2] # Different masses
```
Adjusting these values can create different orbital behaviors.---
## 📌 Todo / Future Improvements
1. Add energy conservation checks.
2. Implement a GUI for user-friendly interaction.
3. Optimize performance for longer simulations.---
## 💡 References
1. Newtonian Mechanics & Three-Body Problem: Wikipedia
2. matplotlib animations: Matplotlib Do---
## 📜 License
This project is open-source and licensed under the MIT License.
📩 Feel free to contribute and improve this simulation!