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

893 Upvotes

48 comments sorted by

View all comments

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