position function

({double dec, double ra}) position(
  1. Planet planet,
  2. Planet earth,
  3. double jde
)

Observed equatorial coordinates of a planet.

planet and earth are VSOP87 Planet objects. Returns right ascension and declination in radians.

Implementation

({double ra, double dec}) position(Planet planet, Planet earth, double jde) {
  // Earth's heliocentric position at equinox of date.
  final posEarth = earth.position(jde);
  final sB0 = math.sin(posEarth.lat);
  final cB0 = math.cos(posEarth.lat);
  final sL0 = math.sin(posEarth.lon);
  final cL0 = math.cos(posEarth.lon);

  // Compute geocentric rectangular coordinates.
  ({double x, double y, double z}) computePos(double tau) {
    final pos = planet.position(jde - tau);
    final sB = math.sin(pos.lat);
    final cB = math.cos(pos.lat);
    final sL = math.sin(pos.lon);
    final cL = math.cos(pos.lon);
    return (
      x: pos.range * cB * cL - posEarth.range * cB0 * cL0,
      y: pos.range * cB * sL - posEarth.range * cB0 * sL0,
      z: pos.range * sB - posEarth.range * sB0,
    );
  }

  // First pass — no light-time correction.
  var p = computePos(0);
  final delta = math.sqrt(p.x * p.x + p.y * p.y + p.z * p.z); // (33.4)
  final tau = lightTime(delta);
  // Second pass — with light-time correction.
  p = computePos(tau);

  var lambda = math.atan2(p.y, p.x); // (33.1)
  var beta = math.atan2(p.z, math.sqrt(p.x * p.x + p.y * p.y)); // (33.2)

  // Ecliptic aberration.
  final ab = apparent.eclipticAberration(lambda, beta, jde);
  lambda += ab.dLon;
  beta += ab.dLat;

  // FK5 correction.
  final fk5 = toFK5(lambda, beta, jde);
  lambda = fk5.lon;
  beta = fk5.lat;

  // Nutation.
  final n = nut.nutation(jde);
  lambda += n.dPsi;
  final eps = nut.meanObliquity(jde) + n.dEps;

  // Ecliptic to equatorial.
  return eclToEq(lambda, beta, math.sin(eps), math.cos(eps));
}