A Physically Accurate Orbital Mechanics Simulator with Kepler's Equation Implementation
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.
The simulation implements Kepler's Equation to determine planetary positions:
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
Converting eccentric anomaly to true anomaly (ν):
This yields the actual angular position of the planet in its orbit.
Calculating orbital radius at any point:
Where:
- a = Semi-major axis (AU)
- r = Heliocentric distance at time t
Mean angular velocity (n):
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
- 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
- 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
- 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
- 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
- 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
// 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- Mean Anomaly Propagation: Calculate M = n·t (mod 2π)
- Kepler Equation Solver: Iterate E = M + e·sin(E) until convergence
- True Anomaly Computation: Convert E → ν using two-argument arctangent
- Radius Calculation: Determine r from semi-major axis and eccentric anomaly
- Cartesian Conversion: Transform polar (r, ν) to Cartesian (x, y) coordinates
- Focal Translation: Offset by c = ae to position Sun at focus
- Screen Mapping: Scale AU to pixels and center on canvas
// 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()- 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
- 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)
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
- JPL Horizons System: Orbital element data
- IAU Standards: J2000.0 epoch reference frame
- NASA: Planetary imagery and texture resources
Experience the simulation instantly: ssdc-simualtion.netlify.app
# 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- Observe: Watch real-time Keplerian orbital motion
- Control Speed: Adjust time rate slider (1-60 Earth years per second)
- Toggle Visibility: Show/hide orbits, Mercury, and Venus
- Customize Appearance: Change orbit color with color picker
- Enable Missions: Activate space settlement transport between Earth-Mars
- Configure Rest Time: Set surface stay duration (0-365 days)
- Pause: Freeze simulation to examine planetary positions
- 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
- 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
- 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
Abhyudaya Gupta - Student & Developer
Built with precision mathematics and celestial passion 🪐✨