Skip to content

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. ๐Ÿš€๐Ÿ”ญ

License

Notifications You must be signed in to change notification settings

SCORLEOs773/Three-Body-Problem-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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:
    git clone https://github.com/yourusername/three-body-simulation.git
    cd three-body-simulation
    
  2. Install the required dependencies:
    pip install numpy matplotlib scipy
    
  3. Run the simulation: a. 2D Version:
    python three_body_2d.py
    b. 3D Version:
    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:

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!

About

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. ๐Ÿš€๐Ÿ”ญ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages