stable.png shows the information needed for calculating the speed an object should have for a stable orbit (given no other objects).

The idea is that initially the direction of the small object m1 (upper left) is perpendicular to the direction towards the bigger object m2, and that after applying the gravitational forces, this should still be the case.

x: forward momentum of m1
f: force applied to m1 by m2
d: distance between m1 and m2

Applying force f to m1 yields the vector x+f, the new direction of m1. Halfway this vector the new direction is perpendicular again, but one step always follows the entire vector. At the end, the direction would be too far outward, and not perpendicular anymore.

This can be solved by applying Pythagoras' theorem not to x^2 + (d-f)^2 = d^2, but to x^2 + (d-f/2)^2 = d^2 instead. At the bottom left you can see that a vector of length f/2 lines up exactly with the middle of vector x+f, where m1's direction would be perpendicular.

See stable.pl for a small script that does the calculating.
