So I've modeled the interactions between the sun and all the planets (and the interactions between the planets) using Verlet integration.

I've used data from Wikipedia for masses, distance from the sun etc.

I initialized the initial velocities of the planets via the critical velocity equation.

This produces nice stable velocities.

I'm unsure of how to calculate the initial velocity of the moon so that it stays in orbit around the earth.


The moon orbits the earth with a near circular trajectory relative to the earth. So add earth's orbital velocity (around the sun) to the moon's orbital velocity (around the earth).

This will put the moon into an orbit around the earth, but might make it a bit more eccentric (elliptical). To correct this you can use angular velocity around the sun with respect to the barycenter (center of mass) of the earth moon system. The resulting initial velocity will then be their velocity around the barycenter (since the earth also orbits the moon) plus the angular velocity of the barycenter times their distance from the sun.

Once you have calculated all of this you might also want to set the momentum of the entire system to zero, since otherwise the center of mass of the entire system will keep on moving with a constant velocity.

  • $\begingroup$ I was combining the velocities you mention - however I made the rather silly mistake of misreading the radius of the moons orbit! I'll also take a look at calculating the COM systems velocity! $\endgroup$ – iasksillyquestions Feb 9 '14 at 20:21
  • $\begingroup$ Here's a demo. listentorick.github.io As you can see, the Moons orbit remains unstable! $\endgroup$ – iasksillyquestions Feb 10 '14 at 13:48
  • $\begingroup$ @iasksillyquestions I am not able to run this, got a total of 14 errors. But I suspect that you made an error when defining the initial conditions (for example with units), or your integration step size is to big. What happens when you use info from this page instead of wikipedia? $\endgroup$ – fibonatic Feb 10 '14 at 17:02
  • $\begingroup$ @iasksillyquestions I also made a javascript simulation some time ago. I used data from the link from my previous comment and got a stable orbit of the moon (without the use of angular velocity): rawgithub.com/fibonatic/GravitySim/master/cartesianV2.html $\endgroup$ – fibonatic Feb 10 '14 at 17:23
  • $\begingroup$ Which browser are you using? Works fine for me in Chrome 19 and Firefox 23? I'll take a look at that data! $\endgroup$ – iasksillyquestions Feb 11 '14 at 12:24

You may have noticed that if you start with the sun at rest, and put Jupiter into the system with an initial velocity to (say) the left, then over time the whole system moves left. (If you haven't noticed this is it worth setting the system up that way and letting it run long enough that you do notice it.)

The trick is to recall that both bodies orbit their combined barycenter and put them in with linear velocities found in the CoM frame.

For the Earth-Moon system you have to do the same thing, and then set the CoM system's velocity relative the Sun as if the pair were a planet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.