# Simulates Orbit [duplicate]

I IT developer, and I would code a small program that simulates the orbit of two bodies, the problem of two bodies eventually. I have no problem on the part programming but I have a little trouble with the calculations to be done to retrieve the position of the second body that is in orbit around the first. Could someone expliqer calculations me or give me a site with a concrete example, such calculations to do to have the orbit of the moon around the earth or the earth around the sun?

• How about this? The only bit you really need is the one-line equation for (Newtonian) gravity between two objects, after that it's just modelling moving bodies. stackoverflow.com/questions/22068178/…
– Andy
Mar 29, 2016 at 16:35
• An easy way to implement this is the Leapfrog Integration. Have a look at the code in this answer.
– pela
Mar 29, 2016 at 18:04

The find the Eccentric anomaly ("E", the angle made by the body, the center of the elliptical orbit and the point of periapsis when the body is closest to the sun) you solve $M=E-e\sin(E)$ (it can be solved by newton's method quickly, though convergence is fastest for roughly circular orbits.