Orbit Sandbox: Newtonian Gravity You Can Fling

After reading this you can launch a body into a stable ellipse, predict its speed and period from the initial conditions, and tell the difference between a bound orbit, a slingshot and genuine three-body chaos.

What the sandbox does, and one orbit to try first

Orbit Sandbox integrates Newton's law of gravity for a set of point masses. You place bodies, give one a velocity by dragging, and the simulator advances every body under the pull of every other body. A heavy star sits at the center by default, so most experiments start as one small planet around one big mass.

Here is the hook. Place a planet to the right of the star, then drag straight up (perpendicular to the line joining them) with a modest speed. The planet falls toward the star, misses, swings around, and comes back to almost exactly where it started. That closed loop is an ellipse, and it repeats. Now drag with a larger speed and the loop stretches into a long cigar. Drag hard enough and the loop never closes: the planet leaves on a hyperbola and never returns. One control, the launch speed, decides all three outcomes.

The trail behind each body is the whole point. A closed trail means a bound orbit. A trail that curves once and flies off means escape. A trail that slowly rotates its long axis means precession.

When to reach for it, and when not to

Use Orbit Sandbox to build intuition for Kepler orbits, to see the transition from bound to escape, to construct a binary star or a planet with a moon, and to watch a three-body system fall apart. It is a teaching model, honest about Newtonian mechanics and nothing more.

Do not use it for real ephemerides. It has no general relativity, so it will not reproduce the 43 arcseconds per century of Mercury's perihelion shift that Newton alone misses. It treats bodies as points, so there are no tides, no spin, no atmospheres. Collisions are handled crudely. And because it is a numerical integrator, very close encounters (where r gets tiny and the force blows up) will lose accuracy no matter how careful the method.

For a chaotic system with a clean phase space to compare against, see the Double Pendulum. For gravity on a much larger scale, the Galaxy Collision Simulator runs thousands of bodies at once.

The law, and why it draws ellipses

Every pair of bodies attracts along the line joining them with a force that shrinks as the square of the distance.

\vec{F} = -G \frac{m_1 m_2}{r^2} \hat{r}

Here G is the gravitational constant, m_1 and m_2 are the two masses, r is the distance between them, and \hat{r} is the unit vector from one body to the other. The minus sign makes the force attractive. Divide by mass to get each body's acceleration, then integrate twice to get position.

Two facts fall out of that single law. First, angular momentum is conserved, which is exactly Kepler's second law: the line from star to planet sweeps equal areas in equal times, so the planet runs fast near the star and slow far away. Second, for a bound orbit the total energy is negative and constant.

E = \frac{1}{2} m v^2 - \frac{G M m}{r}

The first term is kinetic energy, the second is gravitational potential energy of a small mass m near a large mass M. When E \lt 0 the orbit is a closed ellipse. When E = 0 the path is a parabola, the exact escape boundary. When E \gt 0 it is a hyperbola and the body leaves for good.

The escape speed at distance r comes from setting E = 0 and solving for v.

v_{\text{esc}} = \sqrt{\frac{2 G M}{r}}

A perfectly circular orbit needs less, exactly v_{\text{circ}} = \sqrt{G M / r}, which is smaller than escape by a factor of \sqrt{2} \approx 1.414.

A worked circular orbit you can reproduce

Launching the demo planet into a clean circle

Work in the sandbox's own units where G = 1. Take a star of mass M = 1000 at the origin and a planet of mass m = 1 placed at r = 200 to the right. To get a circle, launch perpendicular to the star-planet line at exactly the circular speed.

  1. Circular speed: v_{\text{circ}} = \sqrt{G M / r} = \sqrt{1000 / 200} = \sqrt{5} \approx 2.236.
  2. Escape speed for comparison: v_{\text{esc}} = \sqrt{2} \cdot 2.236 \approx 3.162. Launch above that and the planet leaves.
  3. Orbital period from Kepler's third law, T = 2\pi \sqrt{r^3 / (G M)}. Compute r^3 = 200^3 = 8{,}000{,}000, divide by G M = 1000 to get 8000, take the square root to get 89.44, multiply by 2\pi to get T \approx 561.9 time units.
  4. Total energy: E = \tfrac{1}{2}(1)(2.236)^2 - (1000)(1)/200 = 2.5 - 5 = -2.5. Negative, so bound, as expected for a circle.

Launch instead at v = 2.8 (between circular and escape) and the orbit becomes an ellipse. The launch point is then the perihelion (closest point), because the planet is moving faster than a circle demands and will climb outward.

Watch the orbit change shape with speed

The single most instructive knob is launch speed at a fixed distance. Below circular speed the orbit is an ellipse with the launch point at aphelion. At circular speed it is a circle. Above circular but below escape it is an ellipse with the launch point at perihelion. At or above escape it opens into a parabola or hyperbola.

Energy climbs from deeply negative (tight orbit) to zero at the escape speed marked near v = 3.162, then goes positive for hyperbolic escape.

With the star at mass 1000 and the planet at distance 200, a launch speed of 2.236 gives a circle, speeds between 0 and 2.236 give ellipses with the launch point farthest out, speeds between 2.236 and 3.162 give ellipses with the launch point closest in, and speeds of 3.162 or more send the planet away on an open curve that never returns.

Reading the live readouts

The energy and momentum numbers are your accuracy check. In an isolated system both should stay constant. Watch how much they drift.

Total energy
Kinetic plus potential summed over all bodies. A good symplectic step keeps this bounded: it may wobble by a fraction of a percent each orbit but does not steadily grow. If you see energy climbing without bound, the step is too large for a close encounter.
Total momentum
The vector sum of every body's m\vec{v}. With no external force it is exactly conserved. If the star is pinned in place it is not truly free, so momentum bookkeeping only balances when every mass is allowed to move.
Trail shape
Closed loop means bound. Single sweep then straight-ish departure means escape. A loop whose long axis rotates slowly means precession, which appears once you add a second planet whose pull nudges the first.

A concrete accuracy target: run the circular orbit above for ten periods, about 5619 time units. A symplectic integrator should return the energy to within roughly 0.1\% of its start value, -2.5, so you should read something between -2.5025 and -2.4975. A naive Euler step would instead show the orbit spiraling outward as energy leaks upward.

Common mistakes

Launching along the star-planet line instead of across it. A radial launch sends the planet straight at the star, where r \to 0 makes the force explode and the integrator diverges. Always drag roughly perpendicular for a clean orbit.

A second trap is expecting three comparable masses to behave. They will not. With three or more similar masses the motion is chaotic: shift one launch by a pixel and after a few close passes the whole configuration is unrecognizable. This is not a bug in the simulator, it is the three-body problem, which has no general closed-form solution. Nearby starts diverge exponentially, the same sensitivity you can see cleanly in the Double Pendulum.

A third mistake is reading a slingshot backward. When a light body swings close behind a moving planet, it steals a little of the planet's momentum and speeds up in the star's frame. The planet slows by a tiny amount you would never notice given its huge mass. That momentum trade, not any thrust, is how real spacecraft reach the outer planets.

Related simulations

If chaos is what draws you, the Double Pendulum shows sensitive dependence with a rainbow of nearby starts. To see gravity build structure at scale, try the Galaxy Collision Simulator, and for gravity strong enough to bend light there is Black Hole Lensing. For other field-and-force sandboxes, Magnetic Field Lines and Brownian Motion use the same "set it up and watch" approach.

Frequently asked questions

Why does my orbit slowly spiral in or out?

If it spirals steadily, the integration step is too coarse for the current speed, usually because a body is passing very close to the star. Slow the simulation or spread bodies out. A symplectic step conserves energy well, but no method survives an arbitrarily close encounter with a finite step.

What launch speed gives a perfect circle?

Exactly v = \sqrt{G M / r}, launched perpendicular to the line to the star. In the demo units with M = 1000 and r = 200, that is \sqrt{5} \approx 2.236. A shade less gives an ellipse pinched at the launch point, a shade more gives an ellipse bulging past it.

Why can't the simulator solve three bodies exactly?

Because no one can. The three-body problem has no general closed-form solution; the motion is chaotic for most starting conditions. The simulator integrates it step by step, which is the only option, and small numerical differences grow just as small physical differences would.

Is this how NASA plans missions?

The physics is the same inverse-square law, and slingshots work here for the same reason they work in space. Real mission design adds relativity, precise planetary positions, spacecraft thrust and error margins. This is the intuition layer beneath all of that, not the flight software.