logo
By Lawrence

5 minutes

Draw the Equation

So far we watch the balls and see where they went. With one planet, we can do better: work out the whole path the moment the ball leaves the muzzle.

The orbit's numbers

A ball's orbit around one planet is always the same kind of curve. Only its size and stretch change. Two numbers pin it down:

  1. p, the orbit's width at the planet. Go a quarter turn round from the closest point, and the ball is p away.
  2. e, how stretched it is. 0 is a circle. Between 0 and 1 is an ellipse. 1 is a parabola, and above 1 is a hyperbola.

The speed-12 orbit drawn around the planet. The near point is at 11, the far point at 28.29, and a green line marks p, 15.84, a quarter turn round. e is 0.44.

Both come straight from where the ball starts, r, and how it's moving, v. You don't need to work these by hand. The × and the little hat on r̂ are 3D arrow maths, and the game does them for you:

energy               ε = v²/2 − GM/r          below 0, the ball comes back
spin                 h = r × v                angular momentum
stretch              e = (v × h)/GM − r̂       a vector pointing at the closest point
width                p = h²/GM
the path             r(ν) = p / (1 + e·cos ν) ν is the angle from the closest point

The picture above is the speed-12 shot. The formula puts the far point at 28.2857. The game's own step flies the ball out to 28.2876. They agree to three decimal places.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search