Back to projects

Project

In Progress

Solar System Simulation

A physics-based simulation of our solar system using real orbital mechanics, built with C and Raylib.

Tech Stack

CRaylib
View Source

Overview

This project models the orbits of planets in our solar system using real physics. Rather than animating planets along predetermined paths, the simulation calculates the elliptical orbit of a planet with respect to the sun. The planets orbit the sun with correct relative orbital periods, and velocities. The scale of the planets and the sun are scaled differently to fit the whole system reasonably on the screen. The visualisation allows zooming and panning through the solar system, with time controls to speed up or slow down the simulation. Most planets follow a path which is close to a circle so it's difficult to see the elliptecal shape. Although, Mercury demonstrates this quite well.

Challenges

Getting the physics timestep right was tricky. Too large a step and orbits become unstable; too small and the simulation crawls. Implementing a fixed timestep with interpolation for rendering solved the stability issues while maintaining smooth visuals.

What I Learned

Raylib really started to click for me while working on this project. It makes graphics programming feel surprisingly intuitive, and now that I've got the basics down, I can see all kinds of ways to use it in my projects.

Future Plans

I probably won't develop the simulation much further as the physics start to get seriously complex. That said, eventually I'd like to port it to WebAssembly so I can have a live demo on the project page.