Solar System Simulation
2024Simulation & Physics

Solar System Simulation

A Python-based solar system simulation using Pygame for real-time visualization of planetary orbital mechanics, gravitational interactions, and celestial physics — including accurate Newton's law computations, orbital velocity, escape velocity, and data export to CSV.

Le Défi

  • Accurately simulating gravitational attraction between all planet pairs in real time
  • Decomposing force vectors into x/y components for multi-body orbital paths
  • Maintaining simulation stability across large time step variations

La Solution

  • Implemented Newton's law of universal gravitation with full force decomposition using atan2.
  • Optimized the simulation loop to iterate over all planet pairs efficiently using list comprehension.
  • Added a configurable time-step parameter so users can slow down or speed up the simulation.

Fonctionnalités Clés

  • Real-time gravitational force simulation between all bodies
  • Accurate orbital velocity and period calculations (Kepler's 3rd Law)
  • Moon and Star object support
  • Escape velocity, surface gravity, and orbital period per planet
  • CSV data export for all computed attributes
  • Dynamic logging and error handling

Processus

Phase 01

Designed Planet, Sun, Moon, and Star classes with full physics method suites

Phase 02

Loaded planet data dynamically from a structured CSV file

Phase 03

Added logging decorators to track function entry/exit and execution time

Phase 04

Built a CSV export feature to record computed planetary attributes