By coincidence, Google demoed an example of Google Search using Gemini 3 Pro to generativity create an interactive UI for the three body problem: https://youtu.be/uYQGrK55gxQ?t=21
Tried writing an electrostatic particle simulator in Turbo Pascal 7 with BGI as a teen, a handful of particles before it crawled. Then saw a galaxy collision sim on a CD-ROM magazine disc handling thousands of bodies smoothly. Thought it was assembly tricks.. now I'm sure it's algorithmic (avoiding N**2 runtime) but never dug into the specifics. Are charges vs gravity sims essentially the same n-body problem?
>Are charges vs gravity sims essentially the same n-body problem?
The force falls off as the inverse square of distance in both cases. So they are essentially the same problem. Except that charge can attract or repel and gravity (as far as we know) only attracts.
One thing I'd never really considered before is how frequently bodies get ejected at high speed from the simulation, especially as the number of initial bodies is increased. Suddenly made me realise that the "big bang" which previously seemed a bit of a random and magical theory (obvious question is why would the universe be expanding from a single point when gravity would be immense) now seems a lot more plausible without needing any "magic" to justify it.
Some of the high speed ejections might be due to the approximations used. You can see this with a simple time-stepper when the forces get massive when 2 bodies get very close and that force is then applied for the whole timestep.
I don't doubt that the math allows for escape velocities in some interactions. But I am wondering if, realistically, tidal forces might instead shred the bodies before forces were adequate for a body to achieve escape velocity.
It might be a fun option if bodies that pass really close can merge together or tear each other apart. The latter might add a lot of complexity though.
Would it be incorrect to say the universe was a single point at one time? That's been my layman's understanding - the universe at the start was infinitesimally small (a point) and has been expanding since.
I doubt that most (if not all) are physical. This happens since these are considered as point masses, which can not collide. Instead of a collision you get extremely high forces, which add another layer of unphysical results as the large numbers cause numerical problems.
Relating any of this to the big bang is not appropriate at all.
The universe isn't really expanding from a single point though, not in the sense that objects were flung away from that point into a vacuum like the objects in this simulation
Oh one question I have, when I messed around with ThreeJS line width was a problem, these curves look pretty nice/thick on mac, maybe that was updated recently. (lines as in orbit path)
ThreeJS is awesome btw, I exported a GDB file I think from a CAD program and imported it into ThreeJS/able to animate each part pretty cool.
I'm using https://threejs.org/docs/#Line2 which does support variable thickness - you can change this via the Trail Thickness slider. I think older versions did have some issues with line width.
You might be using the webgl lines (LINE_STRIP), those are always thin. The other way is to build a mesh that looks like a line (which Three.js also has functions for). select the line type here to see the difference: https://threejs.org/examples/?q=lines#webgl_lines_fat
Just beautiful. I love that the pattern appears stable but diverges after 5 mins or so. Is the initial state proven to be stable under exact conditions?
My dumb question: I thought the whole thing with this is the instability/inability to predict. It starts off with the three bodies locked in to fixed motions? I guess it has to be for the user to start messing around with it?
There is no general closed-form solution to the three-body problem. There are certain specific initial conditions which give periodic, repeating orbits. But they are almost always highly "unstable", in the sense that any tiny perturbations will eventually get amplified and cause the periodic symmetry to break.
It's analogous to balancing an object on a sharp point. Mathematically, you can imagine that if the object's center of gravity was perfectly balanced over the point, then there would be zero net force and it would stay there forever. But the math will also tell you that any tiny deviation from perfect balance will cause the object to fall over. It's an equilibrium, but not a stable equilibrium.
The example at the link demonstrates this. The numerical integration can't be perfectly accurate, due to both the finite time steps and the effects of floating-point rounding. Initially the error is much too small to see, and the orbits seem to perfectly repeat. But if you wait a couple of minutes, the deviations get bigger and bigger until the system falls apart into chaos.
Not really. Any solar system proves a kind of stability. And so does the famous KAM theorem.
It states that a periodic solution is indeed quasi-stable under small pertubations. And yes, small sometimes is extremely small. But still stable. Imagine a sharp point with a tiny dent.
Awesome project! A browser-based 3D Three-Body simulator makes complex physics concepts interactive and easier to visualize—great for students and enthusiasts alike.
This is really lovely work! Simple to use, surprisingly solid, and just a pleasure to poke around with. The fact it runs in the browser is a bit of magic on its own.
One idea for later might be a few preset systems, such as Alpha Centauri or other known three-body systems. It would give people a quick way to drop into something real before they start making chaos of their own.
Thanks so much, really appreciate it! I’ve been focusing the presets on stable or interesting solutions that aren’t tied to real systems, but adding a few real examples like Alpha Centauri would fit in nicely. I’ll keep that on the list for future updates.
I didn’t realize something until I used this simulation: with three bodies you can eject one body in one direction and the barycentre of the remaining two in another. This means that compared to the original frame of reference you have an orbiting pair that moves.
It’s one of those things that seems so obvious and yet actually seeing it is a really important step in understanding.
There are animations of how the solar system as a whole moves through space. (The solar system isn’t stationary within our galaxy.) The planets therein are forming spirals around the trajectory of the sun in a similar fashion.
I triggered some bug by pausing the simulation, setting the mass of one of the objects to 29.1, then resuming. The lighter objects bounced into the massive objects a few times, then all three objects were suddenly ejected with a very high velocity.
Thank you! Your 2D version is great, I love seeing how different people approach this stuff. As for integrators, I currently only have Velocity Verlet and RK4 (can change in the advanced settings). I started with just Verlet, but to get some of the presets to behave properly I ended up needing RK4 as well. I’ve been thinking about adding adaptive methods next, but I'll take a look at the methods you've got listed too. Everything is still running in plain JS for now. I started moving some of the work into web workers but haven’t finished that part yet.
Symplectic integrators are the approach I used for some old galaxy simulations. Page 5 on the attached paper was my main reference, eq 22
https://arxiv.org/pdf/cond-mat/0110585
I believe this is used in several academic codes for long term N-body calculations.
I'm not sure which ones are you talking about specifically. But there are some with some heavy symmettrical patterns indeed. To my eyes some are mesmerizing to watch.
The orbits are computed in real time, so yeah what you are seeing (modulo errors in my code is genuine)
There are some caveats though. Some orbits are periodic only in a rotating frame of reference.
EDIT: you can share the URL and I can see which orbits you are talking about
Yes, but this would slow the simulation right down if 2 bodies are very close. I think people sometimes use a 'fudge factor', e.g. if distance < x then treat distance as x.
Yes, the softening factor keeps the forces from getting too big when bodies get close together. Better for the visualization but not very accurate to leave it in.
What you describe is the Euler method, which is well known for being a comparatively bad choice in most situations. The ODE solver can be selected, the default is RK4, which is a Runge–Kutta method of 4th order, it computes the next time step by combining the values at 4 previous time steps.
Were you by any chance inspired to make this because of the three body series by Cixin Liu? Or were you moreso just inspired because the simulation/math/physics are interesting?
Thanks! The Three-Body series definitely helped spark the idea, and the URL is a little nod to the books. I also took some simulation classes back in college, so the math and physics side pulled me in too. It’s crossed my mind that it could be fun to add a kind of Trisolaran mode that tracks a small planet and how habitable its position is throughout the orbits.
This browser-based interactive 3D Three‑Body problem simulator is super cool—beautiful visuals + real physics chaos. It’s a fun way to see how three gravitational bodies interact, and the ability to tweak initial conditions makes the chaos feel almost magical.
Nice! It would be interesting to visualize the total momentum vector, IIRC Verlet being symplectic should be good at preserving symmetries, whereas RK4 is good at conserving energy.
Starting out with the stable preset I had no idea how hard it would be to not make a object slingshot out. But it is a really fun sim, I think I will let my kid play with it.
I spent a long time playing with the sim. Nice work.
Most of the random data sets that I ran ended up with a two body system, where the third body was flung far into space never to return. However, some of these were misleading. I had one running for 15 minutes at 5x, and the third body did eventually return.
Question, can you mathmatically plot a trajectory across time X and energy required to see when it's met and how long it would take given a start position or something? Or is the simulation so complex that you can never project.
Oh never mind I see answers to this elsewhere here, cheers.
> However, some of these were misleading. I had one running for 15 minutes at 5x, and the third body did eventually return.
That's not misleading. Real three-body orbital systems show this same behavior. Consider that such a system must obey energy conservation, so only a few extreme edge cases lose one of its members permanently (not impossible, just unlikely).
Ironically, because computer simulators are based on numerical DE solvers, they sometimes show outcomes that a real orbital system wouldn't/couldn't.
I'm just saying that, because of energy conservation, an escaping member would need to permanently carry away more than 1/3 of the system energy (for equal-mass satellites). This is possible but unlikely.
I recently thought that if life supposedly happened by chance then it should be same for the three-body problem: naturally occurred solutions floating here and there somewhere.
The relative scales might be a bit hard to put in the simulation. Roughly 400 to 1 for Earth-Sun to Earth-Moon. It would be fun to set that up and view from Earth and view from Sun though.
With full tidal locking and no external perturbations, it would be permanently stable. If that still bothers you, then consider L4/L5 orbits. An object orbiting around the L4/L5 points in a 3-body system will be perpetually stable so long as there is no external perturbations with total energy above the "hill" at the edge of the L4/L5 space.
The 3D presets are the standout here, especially the ones that move in and out of the orbital plane. The interaction feels smooth, and it’s great to see this level of detail running in the browser.
Will this simulate the sun and planets of the solar system?
Do these models of n-body gravity predict the perihelion in the orbit of Mercury?
Newton's does not predict perihelion, GR General Relativity does, Fedi's SQG Superfluid Quantum Gravity with Gross-Pitaevskii does, and this model of gravity fully-derived from the Standard Model also predicts perihelion in the orbit of planet Mercury.
Lagrange points like L1 and L2 are calculated without consideration for the mass of the moon.
No, and please don’t try to learn anything from that science-free series. The author doesn't even have a Wikipedia-level understanding of what he is writing about.
N-body problems for N>3 do not have exact, closed form solutions. For N=2 the solution is an ellipse. For N=3+ there is no equation you can write down that you can just plug in t and get any future value for the state of the system.
But that is NOT the same as saying it is unpredictable. It is perfectly predictable. You just have to use one of the many numerical solutions for integrating ODEs.
The link points to one of the stable solutions, and there are actually quite a few of those. The problem is that there’s no general closed form that tells us exactly where the bodies will be in the future, so we rely on numerical methods to approximate the motion. If you hit Reset All a few times or add more bodies, you’ll start to see the chaos
An interesting corollary to this is that even if the future trajectory of a general 3-body orbit is predictable in theory using numerical methods (and infinite precision calculations), in practice the use of finite-precision floating point means that after some time the trajectory predicted by an ODE solver will diverge from the mathematically-true trajectory. Even symplectic integrators have this problem. More details on the general case of chaos are provided by this insightful blog post:
There actually is an analytical solution using a power series that actually converges (Karl Sundman's work). Unfortunately, the universe still mocks our attempts. Though the series converges, it does so incredibly slowly. From Wikipedia:
The corresponding series converges extremely slowly. That is, obtaining a value of meaningful precision requires so many terms that this solution is of little practical use. Indeed, in 1930, David Beloriszky calculated that if Sundman's series were to be used for astronomical observations, then the computations would involve at least 10^8000000 terms.
> the computations would involve at least 10^8000000 terms.
Well we could speed up that simulation pretty easily, just arrange the actual masses and velocities somewhere...
Then I thought, is there a way to scale the distances, masses and velocities to create a system with the same, but proportionally faster behavior?
One guess as to perhaps why not: As distances get small, normal matter bodies will get close enough to actually collide. Perhaps some tiny primordial black holes would be useful.
When you say 'stable' here, do you mean 'periodic' or are these solutions actually stable in the face of small perturbations (as opposed to the sensitive dependence on initial conditions that we'd expect from a chaotic system)?
Computing the trajectory of a 3 body problem is a comparatively simple task.
The two grains of truth are that the solutions for most starting conditions are not analytic, roughly meaning that they can not be expressed in terms of functions. The other being that the numerical solution to an ODE diverges exponentially.
> No physics expert but isn't this unpredictable (based on what I saw in series) ?
A three-body orbital problem is an example of a chaotic system, meaning a system extraordinarily sensitive to initial conditions. So no, not unpredictable in the classical sense, because you can always get the same result for the same initial conditions, but it's a system very sensitive to initial settings.
> Amd this does seem predictable, I saw this for almost a minute
The fact that it remains calculable indefinitely isn't evidence that it's predictable in advance -- consider the solar system, which technically is also a chaotic system (as is any orbital system with more than two bodies).
For example, when we spot a new asteroid, we can make calculations about its future path, but those are just estimates of future behavior. Such estimates have a time horizon, after which we can no longer offer reliable assurances about its future path.
You mentioned the TV series. The story is pretty realistic about what a civilization would face if trapped in a three-solar-body system, because the system would have a time horizon past which predictions would become less and less reliable.
I especially like the Three Body Problem series because, unlike most sci-fi, it includes accurate science -- at least in places.
> There are stable solutions. See: Earth’s Moon (or any other planetary moon in the solar system).
Those are not stable solutions. Remember that Earth's moon only came into existence because of a collision with a protoplanet in the past, and if a large enough body passed close by in the future, we might lose our moon -- all because of the complexity of orbital systems with more than two members.
> (or any other planetary moon in the solar system)
There are any number of examples of planets gaining and/or losing moons because of multi-body orbital complexity.
If you are presupposing external perturbations or collisions, it's not an N=3 system... we're talking about the three body problem. A tidally locked system with periodic resonance is permanently stable in the absence of external forces.
Simulating a four-body problem from the point of view of a telluric planet being juggled around by three stars. It's supposed to emulate the evolution of trisolarans from the "Three Body Problem" novel by Liu Cixin.
> Open to suggestions for additional presets or features!
Anaglyphic (red/cyan) 3D rendering would be nice. I've created a lot of anaglyphic 3D apps over the years, but they're no longer very popular -- I suspect it's the goofy glasses one must acquire and wear.
But a true 3D view of an orbital simulator like this greatly increases its impact and tutorial value.
I do not currently have a set of those glasses so I can't test it, but three.js has this and it's pretty easy to add. There should be an "Anaglyph 3D" checkbox at the bottom of the configuration settings. Let me know if you are able to test it out.
Thanks! I tried the anaglyphic option, but the data being provided to the engine doesn't include third dimension data (so the orbits are essentially flat in the third dimension). Also the orbital colors interfere with the anaglyphic effect (which normally expects white graphic data that it then splits into red and cyan).
I think adding third-dimension data would solve or mitigate the other issues, because full-color anaglyphs are possible, although at a reduced degree of subjective separation between the views.
Thanks for pointing out to me that an anaglyphic option is present, which I managed not to notice the first time.
Anyway, with third-dimension data, the anaglyph option ought to work -- for hard-core, old-fashioned red-blue eyeglass wearers. :)
I just added that option. It wasn’t there when you initially looked :). Are you using one of the 3D presets/random config or are you using a 2D preset?
An LLM couldn't provide results for a sim like this, compared to a relatively simple numerical differential equation solver, which is how this sim works. Unless you're asking whether a sim like this could be vibe-coded, if so, the answer is yes, certainly, because the required code is relatively easy to create and test.
Apart from a handful of specific solutions, there are no general closed-form solutions for orbital problem in this class, so an LLM wouldn't be able to provide one.
Part of the Gemini 3 Pro marketing release demonstrated that search results can include interactive UI elements like a simulation of the three body problem https://youtu.be/uYQGrK55gxQ?t=21
Yeah, I used Claude Code, definitely started as a vibe-coded thing. First pass was just basic physics + Three.js rendering. But once I saw it working, I spent some more time on better numerical stability and adding presets from stable 3D orbits, so it turned into more of a real project.
fuck this is so cool. im currently reading deaths end from the three body trilogy and seeing the physical representation is so cool. Makes a certain moment in deaths end seem awesome.
By coincidence, Google demoed an example of Google Search using Gemini 3 Pro to generativity create an interactive UI for the three body problem: https://youtu.be/uYQGrK55gxQ?t=21
Tried writing an electrostatic particle simulator in Turbo Pascal 7 with BGI as a teen, a handful of particles before it crawled. Then saw a galaxy collision sim on a CD-ROM magazine disc handling thousands of bodies smoothly. Thought it was assembly tricks.. now I'm sure it's algorithmic (avoiding N**2 runtime) but never dug into the specifics. Are charges vs gravity sims essentially the same n-body problem?
>Are charges vs gravity sims essentially the same n-body problem?
The force falls off as the inverse square of distance in both cases. So they are essentially the same problem. Except that charge can attract or repel and gravity (as far as we know) only attracts.
They might have been using the fast multipole expansion method
One thing I'd never really considered before is how frequently bodies get ejected at high speed from the simulation, especially as the number of initial bodies is increased. Suddenly made me realise that the "big bang" which previously seemed a bit of a random and magical theory (obvious question is why would the universe be expanding from a single point when gravity would be immense) now seems a lot more plausible without needing any "magic" to justify it.
Some of the high speed ejections might be due to the approximations used. You can see this with a simple time-stepper when the forces get massive when 2 bodies get very close and that force is then applied for the whole timestep.
I don't doubt that the math allows for escape velocities in some interactions. But I am wondering if, realistically, tidal forces might instead shred the bodies before forces were adequate for a body to achieve escape velocity.
It might be a fun option if bodies that pass really close can merge together or tear each other apart. The latter might add a lot of complexity though.
The universe didn’t expand from a single point in the Big Bang, that’s a common misconception: https://lweb.cfa.harvard.edu/seuforum/faq.htm#m9
https://lweb.cfa.harvard.edu/seuforum/questions/#:~:text=EVO...
https://ned.ipac.caltech.edu/level5/Peacock/Peacock3_3.html
Would it be incorrect to say the universe was a single point at one time? That's been my layman's understanding - the universe at the start was infinitesimally small (a point) and has been expanding since.
I doubt that most (if not all) are physical. This happens since these are considered as point masses, which can not collide. Instead of a collision you get extremely high forces, which add another layer of unphysical results as the large numbers cause numerical problems.
Relating any of this to the big bang is not appropriate at all.
The universe isn't really expanding from a single point though, not in the sense that objects were flung away from that point into a vacuum like the objects in this simulation
Oh one question I have, when I messed around with ThreeJS line width was a problem, these curves look pretty nice/thick on mac, maybe that was updated recently. (lines as in orbit path)
ThreeJS is awesome btw, I exported a GDB file I think from a CAD program and imported it into ThreeJS/able to animate each part pretty cool.
I'm using https://threejs.org/docs/#Line2 which does support variable thickness - you can change this via the Trail Thickness slider. I think older versions did have some issues with line width.
You might be using the webgl lines (LINE_STRIP), those are always thin. The other way is to build a mesh that looks like a line (which Three.js also has functions for). select the line type here to see the difference: https://threejs.org/examples/?q=lines#webgl_lines_fat
oh yeah those look great
Just beautiful. I love that the pattern appears stable but diverges after 5 mins or so. Is the initial state proven to be stable under exact conditions?
Suggestion: add a preset for a configuration of the Painleve conjecture. https://en.wikipedia.org/wiki/Painlev%C3%A9_conjecture
My dumb question: I thought the whole thing with this is the instability/inability to predict. It starts off with the three bodies locked in to fixed motions? I guess it has to be for the user to start messing around with it?
Not a dumb question at all!
There is no general closed-form solution to the three-body problem. There are certain specific initial conditions which give periodic, repeating orbits. But they are almost always highly "unstable", in the sense that any tiny perturbations will eventually get amplified and cause the periodic symmetry to break.
It's analogous to balancing an object on a sharp point. Mathematically, you can imagine that if the object's center of gravity was perfectly balanced over the point, then there would be zero net force and it would stay there forever. But the math will also tell you that any tiny deviation from perfect balance will cause the object to fall over. It's an equilibrium, but not a stable equilibrium.
The example at the link demonstrates this. The numerical integration can't be perfectly accurate, due to both the finite time steps and the effects of floating-point rounding. Initially the error is much too small to see, and the orbits seem to perfectly repeat. But if you wait a couple of minutes, the deviations get bigger and bigger until the system falls apart into chaos.
Ahh okay I'll let it run as is for a while and see what happens, thanks
Not really. Any solar system proves a kind of stability. And so does the famous KAM theorem. It states that a periodic solution is indeed quasi-stable under small pertubations. And yes, small sometimes is extremely small. But still stable. Imagine a sharp point with a tiny dent.
Awesome project! A browser-based 3D Three-Body simulator makes complex physics concepts interactive and easier to visualize—great for students and enthusiasts alike.
Looks very nice!
I think I found a bug: after pausing, moving a body and unpausing, I cannot move the camera. Changing "follow" to something and back to "none" helps.
This should be fixed!
How about a perturb button so those special stable orbits can be nudged just enough to destabilize them.
Pause, choose a body, tweaks its mass, resume.
It destabilized after a few minutes on my phone.
This is really lovely work! Simple to use, surprisingly solid, and just a pleasure to poke around with. The fact it runs in the browser is a bit of magic on its own.
One idea for later might be a few preset systems, such as Alpha Centauri or other known three-body systems. It would give people a quick way to drop into something real before they start making chaos of their own.
Anyway, cracking project.
Thanks so much, really appreciate it! I’ve been focusing the presets on stable or interesting solutions that aren’t tied to real systems, but adding a few real examples like Alpha Centauri would fit in nicely. I’ll keep that on the list for future updates.
I didn’t realize something until I used this simulation: with three bodies you can eject one body in one direction and the barycentre of the remaining two in another. This means that compared to the original frame of reference you have an orbiting pair that moves.
It’s one of those things that seems so obvious and yet actually seeing it is a really important step in understanding.
There are animations of how the solar system as a whole moves through space. (The solar system isn’t stationary within our galaxy.) The planets therein are forming spirals around the trajectory of the sun in a similar fashion.
I triggered some bug by pausing the simulation, setting the mass of one of the objects to 29.1, then resuming. The lighter objects bounced into the massive objects a few times, then all three objects were suddenly ejected with a very high velocity.
This is amazing! Nicely done!
I did something similar, mostly 2D here:
https://www.nhatcher.com/three-body-periodic/
(Mine is just unfinished)
Thank you! Your 2D version is great, I love seeing how different people approach this stuff. As for integrators, I currently only have Velocity Verlet and RK4 (can change in the advanced settings). I started with just Verlet, but to get some of the presets to behave properly I ended up needing RK4 as well. I’ve been thinking about adding adaptive methods next, but I'll take a look at the methods you've got listed too. Everything is still running in plain JS for now. I started moving some of the work into web workers but haven’t finished that part yet.
Symplectic integrators are the approach I used for some old galaxy simulations. Page 5 on the attached paper was my main reference, eq 22 https://arxiv.org/pdf/cond-mat/0110585 I believe this is used in several academic codes for long term N-body calculations.
I would be very curious to compare notes on the integrators you used. How good do they perform in general?
In the avobed shared you can go to the settings a pick an integrator. I did the integrators in wasm although I suspect js is just as fast.
Color me impressed! I love the ammount of settings you can play with. I still need to understand what happens whe yu add more bodies though.
what the heck? are those three orbits genuinely symmetrical in 2D or did I misinterpret
I'm not sure which ones are you talking about specifically. But there are some with some heavy symmettrical patterns indeed. To my eyes some are mesmerizing to watch.
The orbits are computed in real time, so yeah what you are seeing (modulo errors in my code is genuine)
There are some caveats though. Some orbits are periodic only in a rotating frame of reference.
EDIT: you can share the URL and I can see which orbits you are talking about
Like: https://www.nhatcher.com/three-body-periodic/?class=bhh_sate...
Excellent work. Is this based on simple Newtonian gravity applied over a uniform time-step, or something more sophisticated?
For accuracy, time step can get smaller when bodies are closer.
Yes, but this would slow the simulation right down if 2 bodies are very close. I think people sometimes use a 'fudge factor', e.g. if distance < x then treat distance as x.
>'fudge factor'
Maybe that is what the 'softening' parameter relates to?
Yes, the softening factor keeps the forces from getting too big when bodies get close together. Better for the visualization but not very accurate to leave it in.
What you describe is the Euler method, which is well known for being a comparatively bad choice in most situations. The ODE solver can be selected, the default is RK4, which is a Runge–Kutta method of 4th order, it computes the next time step by combining the values at 4 previous time steps.
I see it now, under the 'Advanced' options.
Nice work!
Were you by any chance inspired to make this because of the three body series by Cixin Liu? Or were you moreso just inspired because the simulation/math/physics are interesting?
Thanks! The Three-Body series definitely helped spark the idea, and the URL is a little nod to the books. I also took some simulation classes back in college, so the math and physics side pulled me in too. It’s crossed my mind that it could be fun to add a kind of Trisolaran mode that tracks a small planet and how habitable its position is throughout the orbits.
It was nice of you to add that stable era to the submission URL. It was good while it lasted. Oh well, Time to DEHYDRATE
I think the URL is telling
Nightfall by Asimov was a 7 bodies problem - https://en.wikipedia.org/wiki/Nightfall_(Asimov_novelette_an...
And to be fair, Liu Cixin's book is a 4 bodies problem :)
This made me irrationally annoyed, lol. But that was only the start (I've only seen the TV show though)
Seriously there was so much wrong with that book.
There was a lot right with it as well IMHO. It was very original (I've only read the first book so far).
To each their own, I suppose.
This browser-based interactive 3D Three‑Body problem simulator is super cool—beautiful visuals + real physics chaos. It’s a fun way to see how three gravitational bodies interact, and the ability to tweak initial conditions makes the chaos feel almost magical.
LLM spam ? on my HN ?
LLM spam
Nice! It would be interesting to visualize the total momentum vector, IIRC Verlet being symplectic should be good at preserving symmetries, whereas RK4 is good at conserving energy.
Super cool!
I've been working on some n-body code too, currently native only though: https://www.youtube.com/watch?v=rmyA9AE3hzM
Starting out with the stable preset I had no idea how hard it would be to not make a object slingshot out. But it is a really fun sim, I think I will let my kid play with it.
I spent a long time playing with the sim. Nice work.
Most of the random data sets that I ran ended up with a two body system, where the third body was flung far into space never to return. However, some of these were misleading. I had one running for 15 minutes at 5x, and the third body did eventually return.
It might be fun to add some kind of visualization showing when a body has enough energy to potentially escape the system.
Agree. I was hoping perhaps it would "flash" or do something visually different to indicate "Bye bye!"
Question, can you mathmatically plot a trajectory across time X and energy required to see when it's met and how long it would take given a start position or something? Or is the simulation so complex that you can never project. Oh never mind I see answers to this elsewhere here, cheers.
> However, some of these were misleading. I had one running for 15 minutes at 5x, and the third body did eventually return.
That's not misleading. Real three-body orbital systems show this same behavior. Consider that such a system must obey energy conservation, so only a few extreme edge cases lose one of its members permanently (not impossible, just unlikely).
Ironically, because computer simulators are based on numerical DE solvers, they sometimes show outcomes that a real orbital system wouldn't/couldn't.
I don’t understand. How would energy not be conserved if one flew away? It’s not in the system, but it’s still out there?
I'm just saying that, because of energy conservation, an escaping member would need to permanently carry away more than 1/3 of the system energy (for equal-mass satellites). This is possible but unlikely.
So beautiful, I once had a similar idea, and I'm glad to see someone bring it to life
I recently thought that if life supposedly happened by chance then it should be same for the three-body problem: naturally occurred solutions floating here and there somewhere.
There’s a big one in the sky right now - the Earth-Moon-Sun system.
The relative scales might be a bit hard to put in the simulation. Roughly 400 to 1 for Earth-Sun to Earth-Moon. It would be fun to set that up and view from Earth and view from Sun though.
Give it time…
With full tidal locking and no external perturbations, it would be permanently stable. If that still bothers you, then consider L4/L5 orbits. An object orbiting around the L4/L5 points in a 3-body system will be perpetually stable so long as there is no external perturbations with total energy above the "hill" at the edge of the L4/L5 space.
The 3D presets are the standout here, especially the ones that move in and out of the orbital plane. The interaction feels smooth, and it’s great to see this level of detail running in the browser.
I really enjoyed the book series. This is an amazing work! Thanks for sharing.
Will this simulate the sun and planets of the solar system?
Do these models of n-body gravity predict the perihelion in the orbit of Mercury?
Newton's does not predict perihelion, GR General Relativity does, Fedi's SQG Superfluid Quantum Gravity with Gross-Pitaevskii does, and this model of gravity fully-derived from the Standard Model also predicts perihelion in the orbit of planet Mercury.
Lagrange points like L1 and L2 are calculated without consideration for the mass of the moon.
Additional notes on n-body mechanics: https://westurner.github.io/hnlog/#comment-45928486 Ctrl-f n-body, perihelion
Any github?
No physics expert but isn't this unpredictable (based on what I saw in series) ?
Amd this does seem predictable, I saw this for almost a minute
No, and please don’t try to learn anything from that science-free series. The author doesn't even have a Wikipedia-level understanding of what he is writing about.
N-body problems for N>3 do not have exact, closed form solutions. For N=2 the solution is an ellipse. For N=3+ there is no equation you can write down that you can just plug in t and get any future value for the state of the system.
But that is NOT the same as saying it is unpredictable. It is perfectly predictable. You just have to use one of the many numerical solutions for integrating ODEs.
The link points to one of the stable solutions, and there are actually quite a few of those. The problem is that there’s no general closed form that tells us exactly where the bodies will be in the future, so we rely on numerical methods to approximate the motion. If you hit Reset All a few times or add more bodies, you’ll start to see the chaos
An interesting corollary to this is that even if the future trajectory of a general 3-body orbit is predictable in theory using numerical methods (and infinite precision calculations), in practice the use of finite-precision floating point means that after some time the trajectory predicted by an ODE solver will diverge from the mathematically-true trajectory. Even symplectic integrators have this problem. More details on the general case of chaos are provided by this insightful blog post:
https://www.stochasticlifestyle.com/how-chaotic-is-chaos-how...
There actually is an analytical solution using a power series that actually converges (Karl Sundman's work). Unfortunately, the universe still mocks our attempts. Though the series converges, it does so incredibly slowly. From Wikipedia:
The corresponding series converges extremely slowly. That is, obtaining a value of meaningful precision requires so many terms that this solution is of little practical use. Indeed, in 1930, David Beloriszky calculated that if Sundman's series were to be used for astronomical observations, then the computations would involve at least 10^8000000 terms.
> the computations would involve at least 10^8000000 terms.
Well we could speed up that simulation pretty easily, just arrange the actual masses and velocities somewhere...
Then I thought, is there a way to scale the distances, masses and velocities to create a system with the same, but proportionally faster behavior?
One guess as to perhaps why not: As distances get small, normal matter bodies will get close enough to actually collide. Perhaps some tiny primordial black holes would be useful.
When you say 'stable' here, do you mean 'periodic' or are these solutions actually stable in the face of small perturbations (as opposed to the sensitive dependence on initial conditions that we'd expect from a chaotic system)?
The math in the 3 body problem was made up.
Computing the trajectory of a 3 body problem is a comparatively simple task.
The two grains of truth are that the solutions for most starting conditions are not analytic, roughly meaning that they can not be expressed in terms of functions. The other being that the numerical solution to an ODE diverges exponentially.
> No physics expert but isn't this unpredictable (based on what I saw in series) ?
A three-body orbital problem is an example of a chaotic system, meaning a system extraordinarily sensitive to initial conditions. So no, not unpredictable in the classical sense, because you can always get the same result for the same initial conditions, but it's a system very sensitive to initial settings.
> Amd this does seem predictable, I saw this for almost a minute
The fact that it remains calculable indefinitely isn't evidence that it's predictable in advance -- consider the solar system, which technically is also a chaotic system (as is any orbital system with more than two bodies).
For example, when we spot a new asteroid, we can make calculations about its future path, but those are just estimates of future behavior. Such estimates have a time horizon, after which we can no longer offer reliable assurances about its future path.
You mentioned the TV series. The story is pretty realistic about what a civilization would face if trapped in a three-solar-body system, because the system would have a time horizon past which predictions would become less and less reliable.
I especially like the Three Body Problem series because, unlike most sci-fi, it includes accurate science -- at least in places.
There are stable solutions. See: Earth’s Moon (or any other planetary moon in the solar system).
> There are stable solutions. See: Earth’s Moon (or any other planetary moon in the solar system).
Those are not stable solutions. Remember that Earth's moon only came into existence because of a collision with a protoplanet in the past, and if a large enough body passed close by in the future, we might lose our moon -- all because of the complexity of orbital systems with more than two members.
> (or any other planetary moon in the solar system)
There are any number of examples of planets gaining and/or losing moons because of multi-body orbital complexity.
If you are presupposing external perturbations or collisions, it's not an N=3 system... we're talking about the three body problem. A tidally locked system with periodic resonance is permanently stable in the absence of external forces.
There is also this fun website: https://labs.sense-studios.com/threebody/index.html
Simulating a four-body problem from the point of view of a telluric planet being juggled around by three stars. It's supposed to emulate the evolution of trisolarans from the "Three Body Problem" novel by Liu Cixin.
> Open to suggestions for additional presets or features!
Anaglyphic (red/cyan) 3D rendering would be nice. I've created a lot of anaglyphic 3D apps over the years, but they're no longer very popular -- I suspect it's the goofy glasses one must acquire and wear.
But a true 3D view of an orbital simulator like this greatly increases its impact and tutorial value.
I do not currently have a set of those glasses so I can't test it, but three.js has this and it's pretty easy to add. There should be an "Anaglyph 3D" checkbox at the bottom of the configuration settings. Let me know if you are able to test it out.
Thanks! I tried the anaglyphic option, but the data being provided to the engine doesn't include third dimension data (so the orbits are essentially flat in the third dimension). Also the orbital colors interfere with the anaglyphic effect (which normally expects white graphic data that it then splits into red and cyan).
I think adding third-dimension data would solve or mitigate the other issues, because full-color anaglyphs are possible, although at a reduced degree of subjective separation between the views.
Thanks for pointing out to me that an anaglyphic option is present, which I managed not to notice the first time.
Anyway, with third-dimension data, the anaglyph option ought to work -- for hard-core, old-fashioned red-blue eyeglass wearers. :)
I just added that option. It wasn’t there when you initially looked :). Are you using one of the 3D presets/random config or are you using a 2D preset?
nice simulator…
one issue i have always had with the n-body calculations is how can you be sure there is exactly n?
Is this with Gemini 3?
> Is this with Gemini 3?
An LLM couldn't provide results for a sim like this, compared to a relatively simple numerical differential equation solver, which is how this sim works. Unless you're asking whether a sim like this could be vibe-coded, if so, the answer is yes, certainly, because the required code is relatively easy to create and test.
Apart from a handful of specific solutions, there are no general closed-form solutions for orbital problem in this class, so an LLM wouldn't be able to provide one.
Part of the Gemini 3 Pro marketing release demonstrated that search results can include interactive UI elements like a simulation of the three body problem https://youtu.be/uYQGrK55gxQ?t=21
Well I was wondering if it was vibe coded because Gemini 3 loves Three.js and that's a main selling point of the model.
Yeah, I used Claude Code, definitely started as a vibe-coded thing. First pass was just basic physics + Three.js rendering. But once I saw it working, I spent some more time on better numerical stability and adding presets from stable 3D orbits, so it turned into more of a real project.
This was posted as well to the vibecoding subreddit, where the OP said they used Claude Code.
fuck this is so cool. im currently reading deaths end from the three body trilogy and seeing the physical representation is so cool. Makes a certain moment in deaths end seem awesome.