Demonstrates the siderust C++ API.
Demonstrates the siderust C++ API.Usage: cd build && cmake .. && cmake –build . && ./demo
#include <cmath>
#include <cstdio>
using namespace qtty::literals;
std::printf("=== siderust-cpp demo ===\n\n");
auto jd = JulianDate::from_utc({2026, 7, 15, 22, 0, 0});
std::printf("JD for 2026-07-15 22:00 UTC: %.6f\n", jd.value());
std::printf("Julian centuries since J2000: %.10f\n", jd.julian_centuries());
auto mjd = MJD::from_jd(jd);
std::printf("MJD: %.6f\n\n", mjd.value());
auto obs = ROQUE_DE_LOS_MUCHACHOS;
std::printf("Roque de los Muchachos: lon=%.4f lat=%.4f h=%.0f m\n\n",
obs.lon.value(), obs.lat.value(), obs.height.value());
qtty::Radian sun_alt = sun::altitude_at(obs, mjd);
std::printf("Sun altitude: %.4f rad (%.2f deg)\n\n",
sun_alt.value(), sun_alt.to<qtty::Degree>().value());
const auto& vega = VEGA;
std::printf("Star: %s, d=%.2f ly, L=%.2f Lsun\n",
vega.name().c_str(), vega.distance_ly(),
vega.luminosity_solar());
qtty::Radian star_alt = star_altitude::altitude_at(vega, obs, mjd);
std::printf("Vega altitude: %.4f rad (%.2f deg)\n\n",
star_alt.value(), star_alt.to<qtty::Degree>().value());
std::printf("--- Typed Coordinate API ---\n\n");
std::printf("Typed ICRS (%.4f, %.4f) -> EclMeanJ2000 (%.4f, %.4f)\n",
vega_icrs.
ra().value(), vega_icrs.
dec().value(),
ecl.lon().value(), ecl.lat().value());
std::printf("Typed ICRS -> EquatorialJ2000 (%.4f, %.4f)\n",
eq_j2000.ra().value(), eq_j2000.dec().value());
std::printf("Typed Horizontal: az=%.4f alt=%.4f deg\n\n",
hor.az().value(), hor.al().value());
auto back = ecl.to_frame<
ICRS>(jd);
std::printf("Roundtrip: (%.6f, %.6f) -> (%.6f, %.6f) -> (%.6f, %.6f)\n",
vega_icrs.
ra().value(), vega_icrs.
dec().value(),
ecl.lon().value(), ecl.lat().value(),
back.ra().value(), back.dec().value());
qtty::Radian ra_rad = vega_icrs.
ra().to<qtty::Radian>();
std::printf(
"Vega RA: %.6f deg = %.6f rad\n\n", vega_icrs.
ra().value(), ra_rad.value());
std::printf("--- Typed Ephemeris ---\n\n");
auto earth = ephemeris::earth_heliocentric(jd);
std::printf("Earth heliocentric (typed AU): (%.8f, %.8f, %.8f)\n",
earth.x().value(), earth.y().value(), earth.z().value());
qtty::Kilometer x_km = earth.comp_x.to<qtty::Kilometer>();
qtty::Kilometer y_km = earth.comp_y.to<qtty::Kilometer>();
std::printf("Earth heliocentric (km): (%.2f, %.2f, ...)\n\n",
x_km.value(), y_km.value());
auto moon = ephemeris::moon_geocentric(jd);
std::printf("Moon geocentric (typed km): (%.2f, %.2f, %.2f)\n",
moon.x().value(), moon.y().value(), moon.z().value());
auto moon_r = std::sqrt(moon.x().value() * moon.x().value() + moon.y().value() * moon.y().value() + moon.z().value() * moon.z().value());
std::printf("Moon distance: %.2f km\n\n", moon_r);
auto mars_data = MARS;
std::printf("Mars: mass=%.4e kg, radius=%.2f km\n",
mars_data.mass_kg, mars_data.radius_km);
std::printf(" orbit: a=%.6f AU, e=%.6f\n\n",
mars_data.orbit.semi_major_axis_au,
mars_data.orbit.eccentricity);
auto night_start = mjd;
auto night_end = mjd + 1.0;
auto nights = sun::below_threshold(obs, night_start, night_end, -18.0_deg);
std::printf("Astronomical night periods (sun < -18 deg):\n");
for (auto& p : nights) {
std::printf(" MJD %.6f – %.6f (%.2f hours)\n",
p.start_mjd(), p.end_mjd(),
p.duration_days() * 24.0);
}
std::printf("\nDone.\n");
return 0;
}
Umbrella header for the siderust C++ wrapper library.
Mean ecliptic & equinox of J2000.0.
Mean equatorial of J2000.0 (FK5-aligned).
International Celestial Reference System.
A direction on the celestial sphere, compile-time tagged by frame.
std::enable_if_t< frames::has_frame_transform_v< F, Target >, Direction< Target > > to_frame(const JulianDate &jd) const
Transform to a different reference frame.
std::enable_if_t< frames::has_horizontal_transform_v< F_ >, Direction< frames::Horizontal > > to_horizontal(const JulianDate &jd, const Geodetic &observer) const
Transform to the horizontal (alt-az) frame.
auto to(const JulianDate &jd) const -> decltype(this->template to_frame< Target >(jd))
Shorthand: .to<Target>(jd) (calls to_frame).