Skip to content

Documentation / @interstellar-tools/equations / computeAngle

Function: computeAngle() ​

ts
function computeAngle(
  orbit: Pick<OrbitInterface, 'e' | 'angle' | 'period'>,
  timeStep: TimeStepInterface
): Radians;

Defined in: angle/compute-angle.ts:68

Advances a body along its orbit by one time step and returns its new true anomaly (ν).

The orbit's angle is the starting true anomaly. There is no date input: call this once per frame or step, and feed the result back in as the next angle to move the body over time. To find a body at a given date instead, use trueAnomalyAt.

Step 1: Mean anomaly after the time step (M)

Done by advanceMeanAnomaly: M=M0+n⋅Δt,n=2π|P| where:

  • M0 is the mean anomaly at the start, converted from the true anomaly angle (equal to it when e=0).
  • n is the mean motion, from the period P converted to days. P is a positive duration; a negative one, from data in the old 0.x convention, is read as its absolute value. A positive step always moves the body forward.
  • Δt is timeStep.value in days. It can be any length, and negative to go back in time.

The result is wrapped to [0,2π).

Step 2: Solve Kepler's equation for the eccentric anomaly (E)

M=E−esin⁡(E) is solved numerically by solveKepler.

Step 3: Convert the eccentric anomaly to the true anomaly (ν)

Done by eccentricToTrueAnomaly: ν=2tan−1⁡(1+e1−etan⁡(E2))

Parameters ​

ParameterTypeDescription
orbitPick<OrbitInterface, "e""angle"
timeStepTimeStepInterfaceHow far to advance, in days.

Returns ​

Radians

The true anomaly after the time step, in radians.

Throws ​

RangeError If the orbit's eccentricity is outside 0≤e<1.

Example ​

ts
import { PLANETS } from '@interstellar-tools/constants';
import { computeAngle } from '@interstellar-tools/equations';

const earth = PLANETS.find((planet) => planet.id === 'earth')!;
const timeStep: TimeStepInterface = { value: 1, unit: 'd' };

// Earth's true anomaly one day after its dataset position
const angle: Radians = computeAngle(earth.orbit!, timeStep);

See ​