Moon phase properties and illumination-window searches.
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace qtty::literals;
template <
typename T>
static CivilTime to_utc_civil(
const T &time) {
return time.template to<scale::UTC>().to_civil();
}
void print_periods(
const std::string &label,
const std::vector<
Period<TT, MJD>> &periods) {
std::cout << "\n" << label << ": " << periods.size() << " period(s)" << std::endl;
for (const auto &p : periods) {
auto dur_h = p.duration<qtty::Hour>();
auto s = to_utc_civil(p.start());
auto e = to_utc_civil(p.end());
std::cout << " - " << s << " -> " << e << " (" << dur_h << ")" << std::endl;
}
}
int main() {
double lat = 28.762;
double lon = -17.892;
double h_m = 2396.0;
Geodetic site{qtty::Degree(lon), qtty::Degree(lat), qtty::Meter(h_m)};
auto mjd = jd.to<format::MJD>();
auto geo = moon::phase_geocentric(jd);
auto topo = moon::phase_topocentric(jd, site);
std::cout << std::fixed;
std::cout << "Moon phase at 2026-03-01 00:00 UTC" << std::endl;
std::cout << "==================================" << std::endl;
std::cout << std::setprecision(4);
std::cout << "Site: lat=" << lat << " deg, lon=" << lon << " deg, h=" << std::setprecision(0)
<< h_m << " m" << std::endl;
std::cout << "\nGeocentric:" << std::endl;
std::cout << " label : " << moon::phase_label(geo) << std::endl;
std::cout << std::setprecision(4);
std::cout << " illuminated fraction : " << geo.illuminated_fraction << std::endl;
std::cout << std::setprecision(2);
std::cout << " phase angle : " << geo.phase_angle.to<qtty::Degree>() << std::endl;
std::cout << " elongation : " << geo.elongation.to<qtty::Degree>() << std::endl;
std::cout << " waxing : " << std::boolalpha << geo.waxing << std::endl;
std::cout << "\nTopocentric:" << std::endl;
std::cout << " label : " << moon::phase_label(topo) << std::endl;
std::cout << std::setprecision(4);
std::cout << " illuminated fraction : " << topo.illuminated_fraction << std::endl;
std::cout << " illumination delta : " << std::showpos
<< (topo.illuminated_fraction - geo.illuminated_fraction) * 100.0 << std::noshowpos
<< " %" << std::endl;
std::cout << " elongation : " << topo.elongation.to<qtty::Degree>() << std::endl;
auto events = moon::find_phase_events(window, opts);
std::cout << "\nPrincipal phase events in next 35 days: " << events.size() << std::endl;
for (const auto &ev : events) {
auto utc = to_utc_civil(ev.time);
std::cout << " - " << std::setw(13) << std::right << ev.kind << " at " << utc << " UTC"
<< std::endl;
}
auto crescent = moon::illumination_range(window, 0.05, 0.35, opts);
auto quarterish = moon::illumination_range(window, 0.45, 0.55, opts);
auto gibbous = moon::illumination_range(window, 0.65, 0.95, opts);
print_periods("Crescent-like range (5%-35%)", crescent);
print_periods("Quarter-like range (45%-55%)", quarterish);
print_periods("Gibbous-like range (65%-95%)", gibbous);
return 0;
}
tempoch::EncodedTime< Scale, Format > Time
tempoch::CivilTime CivilTime
tempoch::Period< Time< Scale, Format > > Period
double illuminated_percent(const MoonPhaseGeometry &geom)
Get the illuminated fraction as a percentage [0, 100].
Umbrella header for the siderust C++ wrapper library.
Geodetic position (WGS84 ellipsoid).
Options for altitude search algorithms.