sunAltitude function

double sunAltitude(
  1. Ecliptic cOnMoon,
  2. Ecliptic cSun
)

Altitude of the Sun above the lunar horizon.

cOnMoon is selenographic (lon, lat) of a site on the Moon. cSun is selenographic coordinates of the Sun. Returns altitude in radians.

Implementation

double sunAltitude(Ecliptic cOnMoon, Ecliptic cSun) {
  final c0 = math.pi / 2 - cSun.lon;
  final sb0 = math.sin(cSun.lat), cb0 = math.cos(cSun.lat);
  final sTheta = math.sin(cOnMoon.lat), cTheta = math.cos(cOnMoon.lat);
  return math.asin(sb0 * sTheta + cb0 * cTheta * math.sin(c0 + cOnMoon.lon));
}