Skip to content

Creating an accurate simulation of the first 4 planets of the solar system, using Kepler's laws, for SSDC competition 2025.

Notifications You must be signed in to change notification settings

AbhyudayaGup/Simulation-for-SSDC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inner Solar System Simulation For SSDC 2025

A Physically Accurate Orbital Mechanics Simulator with Kepler's Equation Implementation

Live Demo GitHub

Kepler's Laws Real-time Orbital Mechanics Hohmann Transfer


Project Overview

Inner Solar System Simulation is a high-fidelity celestial mechanics simulator implementing authentic Keplerian orbital dynamics to model the motion of Mercury, Venus, Earth, and Mars. The system solves Kepler's Equation iteratively using Newton-Raphson methods, accurately rendering elliptical orbits with the Sun positioned at one focal point—exactly as nature intended.

This educational tool demonstrates two-body problem solutions, mean anomaly propagation, and true anomaly calculations, providing a real-time visualization of planetary positions from May 31, 2081, onwards. Additionally, it features an advanced interplanetary trajectory simulator for space settlement missions between Earth and Mars using optimized Hohmann-like transfer orbits.


Core Mathematical Algorithms

** Kepler's Equation Solver**

The simulation implements Kepler's Equation to determine planetary positions:

$$M = E - e \sin(E)$$

Where:

  • M = Mean Anomaly (angle swept at constant angular velocity)
  • E = Eccentric Anomaly (angle from ellipse center)
  • e = Orbital Eccentricity (0 = circular, <1 = elliptical)

Newton-Raphson Iterative Solution:

E[n+1] = E[n] + (M - E[n] + e·sin(E[n])) / (1 - e·cos(E[n]))

Converges to 10⁻¹⁰ accuracy in ~10 iterations

** True Anomaly Calculation**

Converting eccentric anomaly to true anomaly (ν):

$$\nu = 2 \arctan\left(\sqrt{\frac{1+e}{1-e}} \tan\frac{E}{2}\right)$$

This yields the actual angular position of the planet in its orbit.

** Heliocentric Distance Formula**

Calculating orbital radius at any point:

$$r = a(1 - e \cos E)$$

Where:

  • a = Semi-major axis (AU)
  • r = Heliocentric distance at time t

Mean Motion & Orbital Period

Mean angular velocity (n):

$$n = \frac{2\pi}{T}$$

Where T = orbital period in Earth years

Planetary Data:

  • Mercury: T = 0.2408 years, e = 0.2056
  • Venus: T = 0.6152 years, e = 0.0068
  • Earth: T = 1.0000 years, e = 0.0167
  • Mars: T = 1.8808 years, e = 0.0934

Advanced Features

** Physically Accurate Elliptical Orbits**

  • Focal Point Positioning: Sun placed at one focus of each ellipse (not center)
  • Eccentricity Visualization: Observable difference between circular (Venus) and elliptical (Mercury) orbits
  • Real Orbital Parameters: Uses JPL Horizons data for semi-major axes and eccentricities

** Hohmann Transfer Simulation**

  • 80-Day Transfer Windows: Calculates future planetary positions using propagated mean anomaly
  • Space Settlement Pathfinding: Simulates Earth↔Mars transport with optimal timing
  • Rest Period Dynamics: Configurable surface time (default: 5 days) before return journey
  • Trajectory Visualization: Real-time dotted lines showing transfer paths

** Dynamic Visual Systems**

  • Twinkling Starfield: 180+ procedurally animated stars with 4 different shapes (circles, squares, diamonds, crosses)
  • Parametric Orbit Colors: User-selectable orbital path colors with glow effects
  • Ghost Planet Indicators: 35% opacity future positions showing 80-day ahead predictions
  • Canvas Optimization: RequestAnimationFrame for smooth 60 FPS rendering
  • Multi-Layered Rendering: Background stars → Sun → Orbits → Planets → UI hierarchy

Temporal Accuracy

  • J2000.0 Epoch Reference: Calculations referenced to January 1, 2000, 12:00 TT
  • Simulation Start Date: May 31, 2081 (81.414 years from J2000)
  • Time Conversion: Precise Julian day calculations with leap year accounting
  • Variable Speed Control: 1-60 seconds per Earth year simulation rate

Interactive Control Interface

  • Real-Time Speed Adjustment: Dynamic time-step modification without simulation restart
  • Orbital Visibility Toggle: Show/hide individual planet orbits and paths
  • Planet Selection: Enable/disable Mercury and Venus for focused viewing
  • Color Customization: Live orbital path color modification with hex picker
  • Space Settlement Control: Toggle interplanetary transport simulation

Sophisticated Implementations

Mathematical Foundations

// Kepler's Equation (Newton-Raphson iteration)
E = M + e·sin(E)

// True Anomaly from Eccentric Anomaly
ν = 2·arctan(((1+e)/(1-e))·tan(E/2))

// Heliocentric Position
r = a(1 - e·cos(E))
x = r·cos(ν)
y = r·sin(ν)

// Future Position Prediction (80-day Hohmann transfer)
M_future = M_current + n·Δt
where Δt = 80/365.25 years

Orbital Mechanics Pipeline

  1. Mean Anomaly Propagation: Calculate M = n·t (mod 2π)
  2. Kepler Equation Solver: Iterate E = M + e·sin(E) until convergence
  3. True Anomaly Computation: Convert E → ν using two-argument arctangent
  4. Radius Calculation: Determine r from semi-major axis and eccentric anomaly
  5. Cartesian Conversion: Transform polar (r, ν) to Cartesian (x, y) coordinates
  6. Focal Translation: Offset by c = ae to position Sun at focus
  7. Screen Mapping: Scale AU to pixels and center on canvas

Space Settlement Trajectory Algorithm

// Phase 1: Traveling (Linear Interpolation)
position(t) = start_pos + (end_pos - start_pos)·progress
where progress = (t - t_departure) / t_transfer

// Phase 2: Resting (Planet Tracking)
position(t) = current_planet_position(t)

// Phase 3: Departure Trigger
if (t  t_rest_end):
    new_destination = future_position_of_other_planet
    transition_to_traveling_phase()

Performance Optimizations

Computational Efficiency

  • Cached Starfield: Pre-rendered base layer regenerates only on resize
  • O(n) Planet Rendering: Linear complexity with early-exit conditionals
  • Minimal Reflows: Single-pass rendering with batched draw operations
  • Memory-Efficient: Reuses position objects, no memory leaks

Rendering Optimizations

  • Canvas Layering: Static stars drawn once, planets updated per frame
  • Shadow Blur Conditional: Glow effects only on bright stars (pulse > 0.3)
  • Transform Matrix Reuse: ctx.save()/restore() minimizes state changes
  • Path2D Objects: Efficient shape rendering for varied star types (circles, squares, diamonds, crosses)

Code Architecture

Project Structure:
├── Index.html         # Application shell + SEO metadata
├── calculations.js    # Orbital mechanics engine (492 lines)
│   ├── solveKepler()       # Newton-Raphson Kepler solver
│   ├── draw()              # Main rendering loop
│   ├── generateStarfield() # Procedural star generation
│   └── updateSpaceSettlement() # Hohmann transfer logic
├── code.css          # Glassmorphic UI styling
├── planet textures   # Mercury, Venus, Earth, Mars, SS PNGs
└── README.md         # Technical documentation

Astronomical Data Sources

  • JPL Horizons System: Orbital element data
  • IAU Standards: J2000.0 epoch reference frame
  • NASA: Planetary imagery and texture resources

Getting Started

** Live Demo**

Experience the simulation instantly: ssdc-simualtion.netlify.app

** Local Installation**

# Clone the repository
git clone https://github.com/AbhyudayaGup/Simulation.git

# Navigate to project directory
cd Simulation

# Option 1: Simple file open
start Index.html

# Option 2: Local server (recommended)
python -m http.server 8000
# or
npx serve

# Open browser
http://localhost:8000

Usage Instructions

  1. Observe: Watch real-time Keplerian orbital motion
  2. Control Speed: Adjust time rate slider (1-60 Earth years per second)
  3. Toggle Visibility: Show/hide orbits, Mercury, and Venus
  4. Customize Appearance: Change orbit color with color picker
  5. Enable Missions: Activate space settlement transport between Earth-Mars
  6. Configure Rest Time: Set surface stay duration (0-365 days)
  7. Pause: Freeze simulation to examine planetary positions

Educational Value

Physics Concepts Demonstrated

  • Kepler's Three Laws: Elliptical orbits, equal areas, harmonic law
  • Two-Body Problem: Classical celestial mechanics solution
  • Orbital Elements: Semi-major axis, eccentricity, mean motion
  • Hohmann Transfers: Minimum-energy interplanetary trajectories
  • True vs Mean Anomaly: Angular position representation methods

Mathematical Principles

  • Transcendental Equations: Kepler's equation solution via iteration
  • Numerical Methods: Newton-Raphson convergence analysis
  • Coordinate Transforms: Polar ↔ Cartesian conversions
  • Conic Sections: Ellipse parameterization and focal geometry
  • Trigonometric Identities: Half-angle formulas for true anomaly

Computer Science Concepts

  • Real-Time Rendering: Frame-rate management with requestAnimationFrame
  • Iterative Algorithms: Convergence and error bounds
  • Temporal Integration: Time-step based state propagation
  • Spatial Interpolation: Linear blending for smooth motion
  • Event-Driven Architecture: UI control event handling

Author

Abhyudaya Gupta - Student & Developer

GitHub Live Demo

Built with precision mathematics and celestial passion 🪐✨

About

Creating an accurate simulation of the first 4 planets of the solar system, using Kepler's laws, for SSDC competition 2025.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published