Visual Computing/Astronomy Simulations
1 / 67

05/2024Visual Computing

Astronomy Simulations

A real-time 3-D solar system in the browser — Three.js renders textured planet models orbiting the sun on a hierarchy of pivots, driven from real orbital data, with click-to-focus planet cards and time that stretches from real-time to a month a second.

╌╌╌╌

astra is a real-time solar system that runs in the browser: the sun, the eight planets, and their major moons as textured glTF models drawn with Three.js over WebGL and served from Nuxt. Every body's orbit and physical dimensions come from a Nuxt Content bodies.yml file instead of the source, so correcting a radius or adding a moon is an edit to the data rather than to the geometry.

The planets move at such different rates because of gravity. The sun pulls each one inward with a force that grows as it draws nearer, and for a nearly circular orbit that pull is exactly the centripetal force needed to bend the planet's motion into a loop instead of letting it fly off in a straight line. Balancing the two leaves an orbital speed of , so a planet close to the sun is held tightly, sweeps a short path, and finishes its year quickly, while a distant one drifts. Mercury laps the sun every eighty-eight days at almost 48 km/s; Neptune takes a hundred and sixty-four years at barely a tenth of that.

Gravity sets the pace. The sun pulls every planet inward, and harder the closer it sits (); that pull is exactly what bends the planet's motion () into an orbit instead of a straight line. Setting the pull equal to the centripetal demand gives , so the inner planet races around while the outer one, held far more weakly, drifts.

Rather than recompute that force every frame, astra reads each body's measured orbital speed and radius and moves the planet along its circle directly. On each frame tick advances the body's currentDistance by , wraps it at the orbital circumference, and turns it into an angle around the sun; a second rotation spins the body on its own axis at its real rotation rate, tilted to match its axial tilt. A moon rides its planet's motion and lays its own orbit on top of it, and every planet starts at a random phase, so they never fall into a straight line on load.

Those speeds come straight from the measured orbits:

PlanetOrbital speedYearMoons
Mercury47.9 km/s88 days0
Earth29.8 km/s365 days1
Mars24.1 km/s1.88 years2
Saturn9.7 km/s29.5 years82
Neptune5.4 km/s164 years14

The visualizer below strips the same relationship down to two dimensions, a top-down system where each planet sweeps its ring at a rate set only by its distance from the center.

A top-down slice of astra's core: six planets sweeping their orbits around the sun, each on a faint ring. Hover a planet to light it and its orbit, the way the raycaster does in the 3-D scene. The select is the point — true ratios run each orbit at its real angular rate, so Mercury laps many times before Neptune has crept a few degrees; idealized compresses the range so the whole system stays in motion.
Orbital motion

The clock stretches to taste: a speed control runs it from real time through a day a second up to roughly a month a second (), with a date read-out following the simulated calendar. An idealized mode ignores true scale entirely and drives every orbit at a legible, exaggerated pace, so the whole system is turning visibly the moment it loads instead of appearing frozen.

The camera orbits and zooms under damped controls with panning switched off so the sun stays centered. A raycaster picks out whatever body sits under the cursor and lights it, glowing the model and brightening its orbit ring from a faint fifteen percent to full. Clicking that body slides in a card of its facts (day length, year, moon count, temperature, size against Earth) and retargets the camera to follow it, reframing the zoom to the body's own diameter so the click drops you into a close orbit around it; clicking the sun pulls back out to the whole system.

Behind the planets, a cube-mapped starfield renders first on its own layer so everything composites cleanly over it, and the sun throws a lens flare from a warm point light. Ambient, area, and directional lights around the origin fill in the rest, enough that the planets' far sides still catch light and read against the dark.

astra grew out of a solar-system sketch I wrote in my first term, a 2-D cs1lib program that summed Newton's pairwise pulls on every body each frame. This rebuild trades that live gravity integrator for measured orbital data, textured 3-D models, and a camera you can fly through the system.

References

  1. Project repository
  2. Live site
  3. Reference notes: Linear Algebra

╌╌ END ╌╌