This simulation uses a numerical integration technique called Euler's method to calculate the motions of the celestial bodies over time under the influence of gravity. At each time step, the gravitational force between the bodies is calculated using Newton's law of universal gravitation:
F = G * m1 * m2 / r^2
Where F is the force, G is the gravitational constant, m1 and m2 are the masses of the two bodies, and r is the distance between them.
The force is then used to update the velocity of each body according to Newton's second law of motion (F=ma). The new velocity is added to the current position to determine the body's new position.
This process is repeated many times per second, creating the effect of smooth motion that obeys the laws of physics. The "Time Step" slider controls how many of these update cycles happen per frame of animation.
The starting scenario shown here has the moon placed in a stable circular orbit around the planet. For an orbit to be stable, the inward force of gravity must exactly balance the moon's tendency to continue in a straight line (its inertia).
If the gravity is too weak, the moon's inertia will cause it to escape orbit and fly away. If gravity is too strong, the moon will spiral inward and collide with the planet. The perfect balance leads to the endless, stable orbiting seen in our solar system and beyond!