Show HN: Gravity – Interactive solar-system simulator, from Newton to Einstein

qunabu.github.io
qunabu
2 days ago
197points
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

48 comments

Comments

rfgplkyesterday
Very nice, fairly efficient too.

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.

Syntonicles14 hours ago
This was a lot of fun to explore. I find that naturally I want to click through the animations and observe them for a while before delving into the steps and reading the blurb. It's a bit like skimming around a textbook's headings & figures before reading the chapter, it builds motivation and interest.

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.

jrfloyesterday
I really liked your animations, but isn't step 14 incorrect? Earth's axis processes, but on a very long timescale. In the span of a day, the axis should be effectively stationary. That's why its the rotation 'axis' - it's the fixed line it rotates about. That's why Polaris is the north star: the axis of rotation points effectively directly at it at all times no matter the season. During summer in the northern hemisphere, the tilt is towards the sun, giving us more direct heating, and in the winter it's away from the sun. This isn't due to the axis moving, but due to the axis' relative position changing throughout earth's orbit around the sun.
SamBamyesterday
Everything you're saying is right, but I'm not seeing what's wrong with step 14. Did they edit it?

> 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.

savoyardyesterday
This is exactly right; the phenomenon is known as axial parallelism.
jrfloyesterday
Oh neat, didn't realize there was a term for it!
nonethewiseryesterday
>The Sun’s gravity (red arrow) pulls the Earth straight toward it the whole time — so why no collision? Because the Earth is also moving sideways (green arrow) at 29.8 km/s. Each moment it does fall toward the Sun, but its sideways speed carries it past — it keeps missing. The dashed line shows where inertia alone would send it; gravity bends that straight path into a closed loop. An orbit is simply falling, continuously, and always missing.

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.

matjayesterday
> well that is fortunate

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...

nonethewiseryesterday
yes, exactly. It didn't have to be this way, but it had to be this way to observe it. Survivorship bias.
SamBamyesterday
The tutorial made it seem a little too much like there is only one speed that would keep us in orbit. Any slower and we'd crash, any faster and we'd leave.

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.

DivingForGoldyesterday
Seems like somehow orbiting bodies finally come to an "equilibrium point"... where orbital speed cancels out gravitational pull towards the sun, so a balance is achieved ?
Thiez14 hours ago
It's not as lucky as you think. We formed from the same cloud that made the sun, so the material that made the earth was already in a fairly stable orbit.
VikingCoderyesterday
This is nice.

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!

JKCalhounyesterday
Ha ha, you're looking at the man behind the curtain.

(I thought the same: suspecting it's a kind of crossfade between accreting bodies and finished Earth.)

lgcmo10 hours ago
Very cool!

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

qunabuyesterday
Thank you all for the comments and showing the weaknesses in the model and visualisation. I'll try to understand the issues and fix them soon.
qunabuyesterday
I've just published the first batch of patches and new features. I've learnt a lot during the process and from the comments which was one of the main goals, so I'm really happy about this process. Thanks again!
neurocontrarian5 hours ago
I like it a lot. I'll show to my daughter. Thank you!
artemave17 hours ago
Very nice! Nitpick: the Moon is tidally locked, so it should always face the Earth with the same side.
scamdrill12 hours ago
Really cool and I love educational apps like this. One suggestion is to show the rotation of the earth as the particles come together to form it rather than a static image.