Sun, Earth and Moon
This simulation needs WebAssembly, and it could not start in this browser.
The image is a frame from a real run. Check that JavaScript is on, or try another browser.
The Moon is usually pictured circling the Earth, but the Sun pulls on it about twice as hard as the Earth does. Seen from the Sun, the Moon travels on almost the same orbit as the Earth, weaving slightly inside and outside it, and its path curves toward the Sun at every point. The Earth keeps it anyway, because what acts on the Earth-Moon pair is not the Sun’s pull itself but its difference across the 384,000 km between them, and that tidal difference is small compared with the Earth’s attraction.
This simulation integrates all three bodies with real masses and distances, in astronomical units (AU) and years, where .
What you see
The Sun (yellow) sits at the center, the Earth (blue) circles it once a year at 1 AU, and the Moon (gray) circles the Earth. At true scale the Moon would sit 0.00257 AU from the Earth, less than a pixel here, so the Earth-Moon offset is drawn 40 times larger; the physics uses the true distances. One side effect: the drawn Moon moves around the Earth faster than the Earth moves around the Sun, so its trail forms loops that the real path does not have.
The circle around the Earth marks its Hill sphere, of radius AU (about 1.5 million km), drawn at the same 40-fold scale. Inside it the Earth’s gravity outweighs the Sun’s tidal pull. The Moon orbits at about a quarter of that radius.
The Moon starts at full moon, on the far side of the Earth from the Sun, on a circular orbit around the Earth. It completes a revolution relative to the stars in about 27.5 days and returns to full moon after about 29.7 days, close to the real sidereal and synodic months of 27.32 and 29.53 days. The synodic month is longer because the Earth has moved along its own orbit in the meantime.
Governing equation
with masses and softening AU. In these units a circular orbit at 1 AU has a speed of AU per year, which is the Earth’s starting speed. The ratio of the Sun’s pull to the Earth’s pull on the Moon is
The lunar orbit is short compared with the time step: at the default yr (1.8 days) the integrator takes only about 15 steps per lunar orbit, which keeps the orbit stable but coarse.
Presets
Sun-Earth-Moon (real masses): the standard setup with labels, trails and the Hill sphere shown.
Clean view (no overlays): the same system with labels, trails, the Hill sphere and the force arrows hidden.
High precision (small dt): yr and 16 steps per frame, about 75 steps per lunar orbit. The simulation then advances 0.016 years per frame instead of 0.04, so it runs more slowly.
Parameters
time step dt (yr): 0.0005 to 0.04 years (default 0.005). substeps / frame: 1 to 32 (default 8).
Hill sphere: shows or hides the Hill sphere circle.
integrator and softening: leapfrog and AU by default. A softening length comparable to the Earth-Moon distance weakens their attraction and lets the Moon escape.
The remaining controls change only the drawing.