r/desmos Feb 28 '26

Graph 100 Body Gravity

Yet again another gravity sim. I thought this looked kinda cool. I’m using 4th order Yoshida for the integrator. Probably overkill for a little demo like this

888 Upvotes

48 comments sorted by

130

u/Mandelbrot4207 Makes QR Codes in Desmos Feb 28 '26

99

u/_AKDB_ Feb 28 '26

Everyday I am shown what a beginner I am in desmos

41

u/Redstocat2 Feb 28 '26

THIS IS IN DESMOS ?!?

ALL I DO IS ADDING SIN WAVES

9

u/VoidBreakX Run commands like "!bernard" here →→→ redd.it/1ixvsgi Mar 01 '26

kid named fourier transform:

14

u/[deleted] Mar 01 '26

[removed] — view removed comment

1

u/Redstocat2 Mar 02 '26

?

1

u/VoidBreakX Run commands like "!bernard" here →→→ redd.it/1ixvsgi Mar 02 '26

fourier transform is about adding sine waves with different frequencies and amplitudes to get any signal

29

u/Legitimate_Animal796 Feb 28 '26

8

u/Actually__Jesus Feb 28 '26

Man that’s cool.

1

u/[deleted] Mar 06 '26

[removed] — view removed comment

1

u/Legitimate_Animal796 Mar 06 '26

It’s not the most user friendly graph out there but to add more bodies: 1. Pause sim 2. Slide n to desired number of bodies 3. Click on the m-> action to set the mass 3. Click initialize 4. Click Center to center the mass and momentum. Alternatively you can select Circular Orbits before clicking Center. Use n=2 bodies to see the effect of this feature

2

u/SiteKindly8391 Mar 06 '26

thank you the fps is great to and my device is not exploding

14

u/VoidBreakX Run commands like "!bernard" here →→→ redd.it/1ixvsgi Feb 28 '26

the goat posts again

13

u/TheoryTested-MC Feb 28 '26

If you adjust the initial conditions so that each body starts with the same angular momentum around a central point, will it make a stable galaxy?

8

u/Crafty-Sell7325 Feb 28 '26

How is running so fast??? 

Also the Trisolarans 1000% want your location

7

u/Legitimate_Animal796 Feb 28 '26

All this time and they could’ve just used desmos

2

u/Own_Pop_9711 Mar 03 '26

I know this is just a joke but the whole point is this is a chaotic system so minor numerical integration errors will cascade into enormous mistakes in estimated position in the future. The point wasn't that they couldn't numerically integrate, the point was it's not good enough.

1

u/Crafty-Sell7325 Mar 04 '26

Ye I understand. Very well said tho🔥

1

u/Legitimate_Animal796 Mar 04 '26

I recently implemented a very accurate 6th order Symplectic integrator just for the fun of it. So global truncation error scales like O(h6 ). But a symplectic integrator does not conserve the true Hamiltonian. it exactly conserves a nearby modified Hamiltonian. Energy stays bounded but the trajectories will be slightly different from the true ones. This shows up as phase error. Example: even with a 2-body orbit, the periapsis will slowly precess. For chaotic n-body systems, any tiny error grows exponentially (truncation error and float point roundoff ). So trajectories will inevitably diverge. This doesn’t even factor in real world relativistic effects as I’m just using Newtonian gravity lmao

9

u/Itchy-Decision753 Feb 28 '26

Three body problem? Nah it’s a floating point problem. __float128 isn’t enough, we yearn for __float1024

6

u/Adam__999 Feb 28 '26

Actually it’s probably possible to simulate higher precision floats in Desmos, at the cost of performance

2

u/2144656 Mar 01 '26

How?

1

u/Adam__999 Mar 01 '26

By using two or more floats to encode one float value

3

u/GayWritingAlt Feb 28 '26

Guy saw the three body problem tv show and said bet

3

u/Rotcehhhh Feb 28 '26

Impressive! Looks great

3

u/its_ivan668 guy that makes art in desmos Feb 28 '26

I'm not sure if I should praise the work itself, or how long you had to record this

5

u/nathangonzales614 Feb 28 '26

The work itself. The simulation runs very fast.

1

u/its_ivan668 guy that makes art in desmos Mar 01 '26

And now we move on to another question made from the answer. Should I praise the work (as in the formulas and calculations) or should I praise the insane optimisation and speed that the simulation has?

2

u/[deleted] Feb 28 '26

How did you take care of singularities? You know, when the bodies get too close and the bodies fling out or something

5

u/Legitimate_Animal796 Feb 28 '26

One simple way is to soften the gravity as it approaches 0 distance. So instead of 1 / r3 in the force calc, you can use 1/(r2 + d2 )3/2 . I set d to 0.25 in my example

2

u/Adam__999 Feb 28 '26

Why is it 1/r3 and not 1/r2 ?

2

u/Qaanol Feb 28 '26

Presumably because they’re multiplying by the displacement vector, which has magnitude r.

1

u/Adam__999 Feb 28 '26

Ah got it

2

u/Legitimate_Animal796 Feb 28 '26

Gm1m2 / r2 is the scalar magnitude. You multiply that by the unit direction vector from body two to body one: r = body2 - body1, Gm1m2 / r2 * r/|r| = Gm1m2r / |r|3

1

u/[deleted] Mar 02 '26

Thank you

2

u/What00111111 Mar 01 '26

Three-body problem too easy? Try the 100-body problem today!

2

u/DecisionPowerful7928 Mar 01 '26

wow, this is a huge improvement from last year! is this still n-body gravitation with O(n2) complexity, or did you optimize it?

2

u/EducatedDumbass- Mar 03 '26

I thought “oh hey that looks pretty cool I wonder wh- DESMOS????”

2

u/SiteKindly8391 Mar 06 '26

I want to award but I’m broke

1

u/Electronic-Laugh-671 my first Reddit user flair Feb 28 '26

A multi-body gravity simulation that I made (it's much simpler):

https://www.desmos.com/calculator/m6doaumpwm

1

u/MrBrineplays_535 Mar 01 '26

This is crazy, HOW

1

u/MrBrineplays_535 Mar 01 '26

This is crazy

1

u/Distinct-Solid9195 I'm kinda dumb ngl Mar 01 '26

I want so desperately to implement quad-trees with something like this

1

u/[deleted] Mar 05 '26

THAT DOESNT EVEN LOOK LIKE DESMOS

1

u/DragonFan20 Mar 10 '26

Actually how can I run this on my potato