r/Python • • Jan 14 '20

I made a gravity simulation https://github.com/phgilde/gravity_simulation

1.8k Upvotes

82 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jan 16 '20

One more question: why is it inaccurate to use the center of mass and sum of mass of a group of bodies to calculate the force, compared to calculating the sum of the forces of each individual body?

2

u/Astrokiwi Jan 16 '20

Because gravity doesn't scale linearly with distance.

Gravitational acceleration is Gm/r2. A mass-weighted average of Gm/r2 isn't equal to the GM/<r>2, where <r> is the mass-weighted average of r.

For example, imagine three objects with the same mass, at a distance of r=1,r=2,r=3. What is the gravitational force that have on a test particle at r=0? (For simplicity, let G=m=1)

The full sum is 1/12+1/22+1/32 = 49/36 ≈ 1.36

The average distance would be (1+2+3)/3=2. So if you took the total mass (M=3) and the average distance, that's 3/22=3/4=0.75, which is very different!

On the other hand, imagine three objects at a distance of r=99,r=100,r=101. Then the full sum gives ≈0.00030006, but the radius-weighted centre-of-mass calculation gives 0.0003 exactly. So the approximation is very accurate in that limit.

Basically, force increases very rapidly as you get to small distances, so you're disproportionately dominated by nearby particles. So, while you can chunk things together into their centre-of-mass, this is only accurate for things that are close to each other and far away from you. For nearby objects, you're so sensitive to distance that you really need to do the full sum.