Crash, orbit, or escape is decided the instant you let go
Apogee flings a satellite off a tiny planet with real inverse-square gravity. Whether it crashes, orbits, or escapes is fixed at release by two conserved numbers; the frame-by-frame animation just reveals which.
You drag back from a tiny planet, let go, and a satellite arcs off into black space. For a second it looks like anything could happen. It can't. The moment your finger lifts, the whole future of that launch is already settled: it will crash, it will circle forever, or it will break loose and never come back. The animation you watch afterward isn't deciding the outcome. It's just showing you the one that was locked in at release.
Apogee is a page built around that single fact. One planet, one satellite, one click-drag. Most gravity toys on the web are either a canned loop that plays the same arc every time, or a full N-body sandbox you have to learn before anything satisfying happens. This is neither. The trajectory is real inverse-square gravity, integrated one frame at a time, so every launch is an actual orbital-mechanics result rather than a scripted one. No login, no tutorial, no explanation before the good part.
Two numbers, not a picture
The interesting thing is that Apogee never decides an outcome by watching where the dot goes.
It decides at the instant of release, from the same two conserved quantities Kepler worked out
by hand. In a two-body inverse-square field, a position and a velocity fix the entire path to a
single conic section, forever. So the classifier (src/physics.js)
reads two things off the launch:
- Specific orbital energy: the satellite's kinetic energy minus its gravitational potential, per unit mass. If it's negative, the conic is a closed ellipse and the orbit is bound. If it's zero or positive, the path is a parabola or hyperbola and the satellite is gone. That zero-crossing is exactly the local escape velocity, which is where the app gets its name.
- Periapsis: the closest point the ellipse ever comes to the planet's center. A bound orbit isn't enough on its own, because an ellipse that dips below the surface is a collision. So "orbit" means negative energy and a periapsis that clears the planet.
That's the whole decision tree. Crash is a bound orbit whose periapsis is inside the rock. Orbit is a bound orbit that clears it. Escape is anything with non-negative energy. Doing it this way, instead of with distance thresholds, is what makes "orbit" mean something physically honest: a real closed ellipse, not a dot that happened to stay near the middle for a while.
The one-line difference that keeps orbits from unravelling
Deciding the outcome is the easy half. Actually drawing a stable orbit that keeps looping on screen for minutes is where a naive simulation quietly betrays you. The obvious way to move a body, textbook explicit Euler, computes the force, nudges the position, then updates the velocity, and it leaks energy into the system on every step. Watch long enough and a "stable" orbit slowly spirals outward and unwinds, gaining speed from nothing.
Apogee uses semi-implicit (symplectic) Euler instead, which is almost the same code with the two updates swapped: advance the velocity first, then move the position using that new velocity. That one reordering keeps the total energy bounded instead of drifting, so an orbit that locks in stays put for as long as anyone will sit and watch it. It's a satisfyingly small change for how much it matters.
The honest caveat: these aren't SI units. The planet's gravitational parameter is tuned so trajectories read well on a canvas at screen sizes, not so you could plan a real transfer burn. The physics is correct; the numbers are picked for the eye. It's vanilla JavaScript and the Canvas 2D API, no framework and no build step, with the integrator and the classifier both covered by unit and property tests so the arithmetic is never the thing that lies to you.
Try it
Open Apogee and drag straight away from the planet. Release a short pull first and watch it arc back and scatter into debris. Then pull a little harder to find the stable band, where it snaps into a glowing elliptical loop; hold it for two full orbits and it locks, with a confirmation ring and a running orbit count. Finally, yank it well past the edge and watch it clear the boundary on a hyperbola and leave for good. The live HUD shows velocity, altitude, apoapsis, and periapsis the whole way, so you can see the two numbers that already knew how it would end.
This post is part of the build log: every app my automated factory ships gets written up here, honestly. Browse everything at apps.charliekrug.com. Comments are open below.
Loading comments…