Show HN: Gravity – Interactive solar-system simulator, from Newton to Einstein
Posted by qunabu 7 days ago
Just for fun and self education, I've built this over a weekend to teach myself why orbits exist, not just show planets going around. Something that was never clearly explain to me in school. It opens with a guided tour that builds the idea up step by step: two bodies and the equal/opposite force, inertia (the Sun is removed and Earth just drifts straight), then "an orbit is falling and continuously missing," cosmic velocities with a little rocket, Voyager 1 & 2's real gravity assists (the clock runs the actual 1977–1989 dates so the planets orbit into their grand-tour alignment and the slingshots line up), and it ends on Einstein — gravity as curved spacetime, the classic rubber-sheet well. What's real: every body uses its real radius/mass and J2000 orbital elements; positions come from solving Kepler's equation each frame. You can toggle to an N-body mode (symplectic leapfrog) that shows live energy drift (~1e-6%) so you can see the integrator is honest. The only thing faked is scale — at true scale you can't see anything — so there's a toggle between true scale and a log-remapped "visual" scale, with physics always running in real AU. Tech: TypeScript + Three.js + Vite, fully client-side, no backend, works offline (surface textures are generated procedurally from value-noise; only Earth uses a real image). Source: https://github.com/qunabu/Gravity
Happy to answer questions — and feedback on the physics or the explanations is very welcome. This project might be totally inaccurate in terms of real physics, this is how i do understand this on my own - i'm happy to confront this with reality
Comments
Comment by rfgplk 7 days ago
I don't like the explicit split of Newtonian and relativistic gravity, this is often how it's presented in educational content, but it creates too much confusion; for instance it gives the illusion that they are somehow separate theories even though Newtonian gravity is a limiting case of Einsteinian gravity when v << c and gravitational fields are weak (see Poissons eq for Newtons gravitational potential.
Lastly, you should consider rendering spacetime similar to Alessandro Roussels spacetime visualization https://www.youtube.com/watch?v=wrwgIjBUYVc; probably the best and most innovative one I've seen.
Comment by jrflo 7 days ago
Comment by SamBam 7 days ago
> Earth turns once every 23 h 56 min (one sidereal day) about an axis tilted 23.4° (the blue line). That spin gives us day and night; the tilt gives us the seasons.
Nothing in step 14 to me implies s procession of the axis.
Comment by simon145 2 days ago
I also loved the music and narration, I'm curious what you used to create the narration? I noticed the narrator seemed to struggle with numbers sometimes, for example on step 1: "The Sun is ~333 000× heavier" The ~333 000× portion does not seem to be read properly. Not sure if that's only a problem I am experiencing on my browser though.
Comment by qunabu 2 days ago
Comment by nonethewiser 7 days ago
Reading stuff like this always makes me think "well that is fortunate." Of course there is survivorship bias so its not exactly surprising. But it also makes me wonder what could change the status quo.
I guess these are the things that could change it:
- suns becomes lighter (earth shoots into space)
- earth accelerates (earth shoots into space)
- sun becomes heavier (earth falls into sun)
- earth decelerates (earth falls into sun)
I guess in theory some large interstellar object could pass to close too earth and fling us off into space or into the sun.
Comment by matja 7 days ago
I think that was one of the arguments of the Anthropic principle [1], that there doesn't appear to be any reason why there are 3 spatial dimensions and 1 time dimension, or why the fundamental constants are what they are - but if they weren't then there wouldn't be anyone to exist to say "well that is fortunate".
[1] https://en.wikipedia.org/wiki/Anthropic_principle#Dimensions...
Comment by nonethewiser 7 days ago
Comment by SamBam 7 days ago
In fact, though, if you've ever played any game with orbiting mechanics you'd see that it's extremely difficult to get out of orbit if you're in orbit. Going faster simply increases the size of your orbit, and going slower simply shrinks it.
Note that no space program has ever managed (or tried) to send an object into the sun. We're already starting off with such a high orbital velocity, 30km/s, that we'd need to send a rocket backwards at nearly that speed just to slow it down enough to make it crash into the sun. That would require massively more energy than anything we've ever done before.
Comment by DivingForGold 7 days ago
Comment by Thiez 7 days ago
Comment by VikingCoder 7 days ago
I did laugh at how the Gravity built the Earth, with a tiny North America and all, and then as more mass was accumulated, North America got to get bigger and bigger and bigger!
Comment by JKCalhoun 7 days ago
(I thought the same: suspecting it's a kind of crossfade between accreting bodies and finished Earth.)
Comment by Syntonicles 7 days ago
One simply change to improve the experience is to keep the Next/Back at fixed locations. The animations and transitions are beautiful, and looking away to chase the moving buttons causes me to drop the visual context.
As a workaround I set the height of .tour-body to 900px and the the whole thing became so much more immersive, like the old planetariums.
Comment by qunabu 7 days ago
Comment by qunabu 7 days ago
Comment by artemave 7 days ago
Comment by twosky 4 days ago
Comment by kmaitreys 7 days ago
Comment by AmareshHebbar 3 days ago
Comment by jumploops 7 days ago
It'd be awesome to scale this up to the Milk Way, and beyond, watching everything move in relation to larger time scales.
[0]https://astrorhysy.blogspot.com/2015/03/and-yet-it-moves-qui...
Comment by ck2 7 days ago
no computers, no calculators, barely working telescopes looking at the moons orbiting Jupiter
(don't be limited by episode title, lots of amazing astrophysics in there)
Comment by TheOtherHobbes 7 days ago
https://descanso.jpl.nasa.gov/monograph/series2/Descanso2_S0...
Basically pages and pages of differential equations, either modelled analytically or approximated (as accurately as possible) with Chebyshev polynomials.
Aside from the basic Kepler orbits, everything influences everything else. This doesn't make much of a different in the short term, but space is biiiiig and it doesn't take much for tiny influences to have a measurable effect.
There's a slightly simpler introduction to detailed perturbative planetary orbit calculations in Feynman's Lectures on Physics.
FWIW the solar system isn't unconditionally stable. Even without wandering visitors, there's a small chance Mercury might drift outwards and collide with one of the other Inners in the next few billion years.
Comment by vj-vibing 3 days ago
Comment by xixixao 7 days ago
I also think Saturn's rings don't wobble that fast.
Comment by lgcmo 6 days ago
Just one note about the moon orbit around the Earth, it is far more subtle; almost just orbiting the Sun alongside Earth. I can't explain better than minute physics, highly recommend: youtube.com/watch?v=KBcxuM-qXec
Comment by nerdsniper 7 days ago
Comment by scamdrill 7 days ago
Comment by Retirology 5 days ago
Comment by Invictus1001 7 days ago
Comment by qunabu 7 days ago
Comment by BigTuna 7 days ago
Comment by Iolaum 7 days ago
In any case, nice visualization.
Comment by ck2 7 days ago
there is also likely a planet that passed through and yanked away a lot of debris, most of the simulations for tilt etc. don't work without the mystery missing planet
I could watch PBS Space Time all day for that kind of stuff, often do letting it play in the background on repeat, so much better than the news
* https://www.youtube.com/@pbsspacetime/search?query=planets
Dr. Becky is also awesome
Comment by somat 7 days ago
A good follow up question that nobody knows the answer to is "how much iron is in the sun?" The problem as I understand it is we can only directly see the very outer layer where there is no iron, so the standard answer is statistically none, only fractional percentages. But based on the distribution of elements in the solar system I sort of expect a sizable iron core.
Comment by em-bee 7 days ago
Comment by ziofill 7 days ago
Comment by Tepix 7 days ago
Comment by qunabu 7 days ago
Comment by apiorno 17 hours ago
Comment by stevenalowe 7 days ago
Comment by qunabu 7 days ago
Comment by qunabu 7 days ago
Comment by iainmerrick 7 days ago
If the sim were instead centered on the free space (the top half of the screen) it’d be perfect.
Comment by qunabu 7 days ago
Comment by neurocontrarian 6 days ago
Comment by Brendinooo 7 days ago
Comment by genpfault 7 days ago
How are you handling relativistic effects in the N-body simulation?
Comment by qunabu 7 days ago
Comment by mgianluc 6 days ago
Comment by ThrowawayTestr 7 days ago
Comment by hi083 7 days ago
Comment by maximedeco 5 days ago
Comment by roxana_haidiner 7 days ago
Comment by yattapick 5 days ago
Comment by sameersri2004 7 days ago
Comment by AashmanShukla 7 days ago
Comment by cdogukank 7 days ago
Comment by Xotic007 7 days ago