An interactive 3D solar system simulation built with VPython. It models planetary motion using Newtonian gravity and includes features like meteor impacts and a black hole mode.
#Features
- Simulates the Sun and 9 planets (including Pluto)
- Elliptical orbits initialized using Keplerian mechanics
- Real-time gravitational interactions between bodies
- Meteor spawning with collision detection and explosion effects
- Toggleable black hole replacing the Sun
- Clickable bodies with information display
- Background starfield and asteroid belt
- Orbital trails for visualization
#Controls Mouse click: Select a body and toggle its information panel B: Toggle black hole mode M: Spawn a meteor targeting the selected body R: Reset the simulation
#Physics Model
The simulation uses Newton’s law of gravitation:
F = G * m1 * m2 / r^2
Positions and velocities are updated using the Velocity Verlet integration method for better stability in orbital motion.
#Units:
- Distance: meters (scaled using astronomical units)
- Time step: 3600 seconds (1 hour per step) ======================================================================================================== #Requirements
Install VPython:
pip install vpython
#How to Run
python your_script_name.py
#Project Structure
Body (abstract base class)
Handles physics properties (position, velocity, acceleration) Manages rendering via VPython
Derived classes:
Star Planet Meteor BlackHole
SolarSystemSimulation
Main simulation controller Handles physics updates, rendering, input events, and object lifecycle Key Mechanics
Orbital Initialization: Planets are initialized at perihelion using:
v = sqrt((G * M / a) * ((1 + e) / (1 - e)))
#Collision System:
Meteors collide when within a threshold distance Explosions expand and fade over time Meteors are removed after impact
#Cleanup:
Meteors are removed if they travel beyond 20 AU
#Notes
- Planet sizes are scaled up for visibility
- Distances are scaled down using AU to fit the scene
- Textures are loaded from external URLs
- Possible Improvements
- Add moons and hierarchical orbits
- Camera tracking or follow mode
- GUI controls for simulation speed
- More accurate physics (e.g., relativity near black holes) ======================================================================================================== #License
This project is intended for educational use.