Skip to content

Documentation / @interstellar-tools/equations / solveLambert

Function: solveLambert() ​

ts
function solveLambert(
  r1: Vector3DTupleType,
  r2: Vector3DTupleType,
  dt: number,
  mu: number,
  options?: SolveLambertOptionsInterface
): LambertSolutionInterface;

Defined in: manoeuvres/solve-lambert.ts:110

Solve Lambert's problem: find the orbit that goes from one position to another in a given time.

In universal variables, solve for z

μΔt=(y(z)C(z))3/2S(z)+Ay(z),y(z)=r1+r2+AzS(z)−1C(z),A=sin⁡Δθr1r21−cos⁡Δθ

and recover the velocities from the Lagrange coefficients

f=1−yr1,g=Ayμ,g˙=1−yr2,v1=r2−fr1g,v2=g˙r2−r1g

Where:

  • r1, r2 are the two positions and r1, r2 their lengths (m)
  • Δθ is the angle swept from r1 to r2 (rad)
  • C(z) and S(z) are the Stumpff functions, stumpffC and stumpffS
  • μ is the gravitational parameter (m³/s²)

Units

  • Inputs: r1 and r2 in m, dt in s, mu in m³/s².
  • Output: v1 and v2 in m/s.

Notes

  • One formula for ellipses, parabolas and hyperbolas: z>0 is an ellipse, z<0 a hyperbola. The time of flight grows steadily with z, so this solves for z by bisection, which can't diverge, below z=4π2: single-revolution transfers only.
  • The fastest transfers, seconds across thousands of kilometres, end where the terms of the equation nearly cancel. If fewer than about 8 significant digits would be left, the function throws instead of returning an inaccurate answer. It also throws for a time too long for a single revolution.
  • Two positions allow two transfers, the short way round and the long way. prograde picks the one that goes counterclockwise seen from +z, so Δθ is under 180° when (r1×r2)z≥0; prograde: false picks the clockwise one.
  • At 0° and 180° the transfer plane isn't defined by the two positions, and the function throws. Near 180° the solution exists but is sensitive to small changes in the positions.
  • For a transfer between two circular orbits, the velocity changes are v1 minus the speed of the first orbit and the speed of the second minus v2, as vectors.
In practiceApollo 11, aiming for home

11 032 m/s at −6.48°

At entry interface, 44.8 h and 154.15° round Earth from the edge of the Moon's sphere of influence, 322 000 km out

Chapter V of the Apollo 11 tutorial runs Columbia's orbit back from entry interface to the edge of the Moon's sphere of influence: 44.8 h of falling. Ask Lambert's question for those two positions and that time, and it finds the same orbit: it arrives at the flown entry speed and angle, and leaves the edge at 1 239 m/s. Planners asked the question the other way round, to target the midcourse corrections.

ts
const swept = toRad(154.15); // from the edge to entry interface
const edge: Vector3DTupleType = [
  322e6 * Math.cos(swept),
  -322e6 * Math.sin(swept),
  0
];
const entry: Vector3DTupleType = [6_500_086, 0, 0]; // 121.92 km up
const { v2 } = solveLambert(edge, entry, 161_219, 3.986004418e14);
Math.hypot(...v2); // ≈ 11 032 m/s
toDeg(Math.asin(v2[0] / Math.hypot(...v2))); // ≈ −6.48°

Parameters ​

ParameterTypeDescription
r1Vector3DTupleTypePosition r1 at the start, in m (finite components, not zero).
r2Vector3DTupleTypePosition r2 at the end, in m (finite components, not zero).
dtnumberTime of flight Δt in s (finite, > 0).
munumberGravitational parameter μ in m³/s² (finite, > 0).
options?SolveLambertOptionsInterfaceprograde (default true): the direction of the transfer. Room for more, such as multi-revolution transfers, later.

Returns ​

LambertSolutionInterface

The velocities v1 at r1 and v2 at r2, in m/s.

Throws ​

  • If any input is not finite.
  • If dt <= 0, mu <= 0, a position is zero, the positions are 0° or 180° apart, or dt is too short to solve accurately or too long for a single revolution.

Example ​

ts
// Curtis, Example 5.2: one hour between two positions around Earth
const { v1, v2 } = solveLambert(
  [5_000_000, 10_000_000, 2_100_000],
  [-14_600_000, 2_500_000, 7_000_000],
  3600,
  3.986e14
);
// v1 ≈ [-5 992, 1 925, 3 246] m/s, v2 ≈ [-3 312, -4 197, -385] m/s

See ​