The Universal-Variable Lambert Algorithm
Stumpff functions, one equation for every conic, Newton iteration and verification by propagation
The Stumpff functions. For z > 0, C = (1 − cos√z)/z and S = (√z − sin√z)/√z³; for z < 0 the same with cosh and sinh. At z = 0 they are simply 1/2 and 1/6 — no special case required.
A carries the transfer angle, and its sign carries the direction: positive for the short way, negative for the long way. A = 0 at Δθ = 180°, which is the same singularity in new clothes.
y must be positive for a real solution — the reason the solver has to start in the right place.
z > 0 ellipse, z = 0 parabola, z < 0 hyperbola. For a single revolution the root lies below z = 4π², where C(z) = 0 and the flight time becomes infinite. F increases monotonically with z, so Newton converges once it starts on the right side.
- Compute , and (with the direction rule), then .
- Start-up. Find a with and — for example, march upward from a large negative value. Because is increasing, this places you on the correct side of the root.
- Newton. , with the analytic derivative
- Velocities. , , ; , .
Beware of bugs in the above code; I have only proved it correct, not tried it.