The N-Body Problem

Playing with Universal Gravitational Attraction

This is another example based on Dan Shiffman's book The Nature of Code, and his Coding Train NOC 2 youTube series; specifically episode 2.6.

As with his other examples, Dan does not use real-world length or time or mass units, and basically makes up values for constants such as g and G. I will slightly improve on that in my version by at least including the real values of the constants, even if I go on to modify them with a fudge factor (which could be considered to constitute a scaling of pixels to meters or km) but I will not do a thorough real-world scaling as I do in some other projects.

In this version, we move beyond simple attractor body with satellites that are attrated to it, and on to a more realistic scenario in which N-bodies mutually attract each other. I have also added collisions and rebound.

Frame count:     Remaining satellites: