It makes use of Newton’s Law of Gravitation:
F = G * m1 * m2 / (r * r)
Implemented as follows (making use of the p5.js Vector object):
Additionally, it uses values for Mass and Radii based on actual values for the masses of the planets in our solar system.
And, after randomly placing the masses, it determines what their approximate orbital velocity based by determining the speed that would generate a Centripetal Force equal to the gravitational force at that distance.
Caveat: The objects only experience the gravitational attraction of the “sun” at the center; which in turn does not experience any gravitational force. This allows for a stable system, but lacks the interplay of forces in a true n-body simulation.
(No interactivity implemented yet).
- Wikipedia / Gravitational Force
- Wikipedia / Centripetal Force
- Wikipedia / N-Body Simulation
- p5.js / Vector