Documentation / @interstellar-tools/equations / solveKepler
Function: solveKepler()
ts
function solveKepler(
M: Radians,
e: number,
maxIter?: number,
tolerance?: number
): Radians;Defined in: kepler/solve-kepler.ts:98
Solves Kepler's Equation for the Eccentric Anomaly (
- Newton-Raphson method for fast convergence.
- High-eccentricity solver for extreme orbits (
). - Bisection fallback if the selected solver doesn't return a root.
This is the conversion from mean anomaly to eccentric anomaly. Use eccentricToTrueAnomaly on the result to get the true anomaly.
Mathematical Explanation:
Kepler's equation relates the mean anomaly (
Since this equation cannot be solved algebraically, numerical methods are required.
Solving Strategy:
Handle Special Cases:
- If the orbit is circular (
), then directly. - If the orbit is parabolic (
), an exception is thrown. - If eccentricity is out of range (
or ), a RangeErroris thrown.
- If the orbit is circular (
Select the Best Solver:
- For high eccentricities (
) → Uses solveKeplerHighEccentricity(). - For moderate eccentricities (
) → Uses solveKeplerNewtonRaphson(). - The result is verified against Kepler's equation (
tolerance, modulo). If the solver didn't converge ( NaN), stopped atmaxIter, or settled away from the root, it falls back tosolveKeplerBisection(), which always brackets the root.
- For high eccentricities (
Normalization:
- Kepler's equation is
-periodic ( ), so is first reduced to with norm2pi(). This keeps the solvers in their stable range for any finite, including negative values and many revolutions. - The solution is normalized to
with norm2pi().
- Kepler's equation is
Performance Considerations:
- Newton-Raphson typically converges in 4-5 iterations.
- Bisection fallback ensures robustness for extreme cases.
- High-eccentricity solver prevents instability for
.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
M | Radians | undefined | Mean anomaly ( |
e | number | undefined | Orbital eccentricity ( |
maxIter? | number | 50 | Maximum number of iterations before fallback. |
tolerance? | number | 1e-9 | Convergence criterion for stopping the iteration. |
Returns
The eccentric anomaly (
Throws
RangeError If the eccentricity (
Examples
ts
import { solveKepler } from '@interstellar-tools/equations';
// Example 1: Moderate eccentricity
const M = Math.PI / 4; // 45 degrees in radians
const e = 0.1; // Orbital eccentricity
const result = solveKepler(M, e);
console.log(result); // Output: Eccentric anomaly in radiansts
// Example 2: High-eccentricity orbit (e > 0.9)
const M_high = 1.5; // Mean anomaly in radians
const e_high = 0.95; // High eccentricity
console.log(solveKepler(M_high, e_high)); // Uses high-eccentricity solver