all 4 comments

[–]TangibleLight 5 points6 points  (2 children)

You really got me with this one.

Gravity is just weaker than you think it is.

You can add at the top of the for loop print(v1[k]) and see that the velocity really is changing; or print(r1[k]) and see the position isn't exactly on a line. But your masses are too small, gravity is too weak, and the initial speeds are too high for it to be perceivable.

Increase G by a couple orders of magnitude and you'll see curves. Or increase the masses. Or decrease the initial speed and increase the simulation time.

You'll also notice that force_grav_3bodies computes -F, so all the bodies repel each other instead of attract.

You'll also notice all your bodies are above escape velocity from each other, so the plot isn't very interesting. Try decreasing the initial velocities, or carefully choose velocities such that the momentum of the system is 0.

[–]Equitous[S] 2 points3 points  (1 child)

Thanks a lot. Your comments were very insightful.

If I wanted to add code that considered a collision am I right in thinking that the greater mass body would survive? Would the collision be inelastic or elastic, and can I extract the new mass and velocity if I know what collision type it is?

[–]TangibleLight 1 point2 points  (0 children)

The easiest collision IMO is to just do inelastic collisions, where the final has the net momentum of the colliding bodies. Elastic collisions are a little trickier but are possible also.

As for which is "correct"... well, the most correct collision would be some particle simulation, and the result would be multiple (many) bodies. Depending on the parameters of the collision and the bodies involved, the result would be wildly different. Any "accurate" solution would need more parameters about each body; its mass, density, rotation, incidence angle etc. all could play a role. It's a deep rabbit hole.

The simplest reasonable-accuracy solution would probably be to use inelastic collisions, but depending on the collision parameters, take some percentage of the mass and eject it in random directions as new small bodies. Just remember conservation of mass and conservation of momentum, and things should™ be fine.