Top
Best
New

Posted by qunabu 6 hours ago

Show HN: Gravity – interactive solar-system simulator, from Newton to Einstein(qunabu.github.io)
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

95 points | 23 comments
jrflo 2 hours ago|
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.
nonethewiser 2 hours ago||
>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.

matja 1 hour ago|
> 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...

nonethewiser 19 minutes ago||
yes, exactly. It didn't have to be this way, but it had to be this way to observe it. Survivorship bias.
qunabu 2 hours ago||
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.
rfgplk 3 hours ago||
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.

kmaitreys 1 hour ago||
For something more rigorous, I would like to take this opportunity to share rebound[1], something we use for n-body simulations in our field (planet formation). Perhaps few people here are already familiar with it. It has a Python interface but the C interface is very easy to use as well and has plethora of pre-set examples which can be visualized using GLFW. It's very very cool!

[1]https://github.com/hannorein/rebound

VikingCoder 4 hours ago||
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!

JKCalhoun 2 hours ago|
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.)

ziofill 3 hours ago||
That doesn’t look right: in the 7th panel (too fast it escapes) the force and velocity of earth are constant? 0_o
BigTuna 4 hours ago||
Great job! 14 is misleading though - while the context is one day, the animation depicts axial precession which takes place over ~26,000 years
Iolaum 4 hours ago||
My physics bias would like to see earth forming while it's constituents were orbiting around the sun.

In any case, nice visualization.

em-bee 2 hours ago||
i had the same thought. likewise the sun formed from particles circling around the galactic core. that matters later when it is explained how the sun is moving.
ck2 4 hours ago||
that probably happened a few times as well we "stolen" planets or mass from other star systems in the same baby nursery as our sun

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

* https://www.youtube.com/@DrBecky/videos

stevenalowe 5 hours ago|
Looks great but on mobile the popover covers a quarter of the screen, obscuring the sun
qunabu 5 hours ago|
I should have mentioned that its not mobile friendly so far. I will try to fix this.
qunabu 4 hours ago||
It should be better now
iainmerrick 4 hours ago||
It works pretty well on iPhone, except the descriptive text fills most of the bottom half of the screen, overlapping the sim which is centered on the screen.

If the sim were instead centered on the free space (the top half of the screen) it’d be perfect.

qunabu 4 hours ago||
There a toggle button to show hide description if you missed it
More comments...