siderust-cpp
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
solar_system_bodies_example.cpp
Go to the documentation of this file.
1
11#include <siderust/siderust.hpp>
12
13#include <cmath>
14#include <cstdio>
15
16using namespace siderust;
17
18template <typename PosT>
19static double norm3(const PosT& p) {
20 const double x = p.x().value();
21 const double y = p.y().value();
22 const double z = p.z().value();
23 return std::sqrt(x * x + y * y + z * z);
24}
25
26static void print_planet(const char* name, const Planet& p) {
27 std::printf("%-8s mass=%.4e kg radius=%.1f km a=%.6f AU e=%.6f i=%.3f deg\n",
28 name,
29 p.mass_kg,
30 p.radius_km,
34}
35
36int main() {
37 std::printf("=== Solar System Bodies Example ===\n\n");
38
39 auto jd = JulianDate::from_utc({2026, 7, 15, 0, 0, 0});
40 std::printf("Epoch JD: %.6f\n\n", jd.value());
41
42 auto sun_bary = ephemeris::sun_barycentric(jd);
43 auto earth_bary = ephemeris::earth_barycentric(jd);
44 auto earth_helio = ephemeris::earth_heliocentric(jd);
45 auto moon_geo = ephemeris::moon_geocentric(jd);
46
47 std::printf("Sun barycentric (EclipticMeanJ2000, AU):\n");
48 std::printf(" x=%.9f y=%.9f z=%.9f\n",
49 sun_bary.x().value(), sun_bary.y().value(), sun_bary.z().value());
50 std::printf("Earth barycentric (EclipticMeanJ2000, AU):\n");
51 std::printf(" x=%.9f y=%.9f z=%.9f\n",
52 earth_bary.x().value(), earth_bary.y().value(), earth_bary.z().value());
53 std::printf("Earth heliocentric (EclipticMeanJ2000, AU):\n");
54 std::printf(" x=%.9f y=%.9f z=%.9f\n",
55 earth_helio.x().value(), earth_helio.y().value(), earth_helio.z().value());
56 std::printf("Moon geocentric (EclipticMeanJ2000, km):\n");
57 std::printf(" x=%.3f y=%.3f z=%.3f\n\n",
58 moon_geo.x().value(), moon_geo.y().value(), moon_geo.z().value());
59
60 const double earth_sun_au = norm3(earth_helio);
61 const double moon_dist_km = norm3(moon_geo);
62 std::printf("Earth-Sun distance: %.6f AU\n", earth_sun_au);
63 std::printf("Moon distance from geocenter: %.2f km\n", moon_dist_km);
64
65 const qtty::Kilometer earth_x_km = earth_helio.x().to<qtty::Kilometer>();
66 std::printf("Earth heliocentric x component: %.2f km\n\n", earth_x_km.value());
67
68 std::printf("Planet catalog (static properties):\n");
69 print_planet("Mercury", MERCURY);
70 print_planet("Venus", VENUS);
71 print_planet("Earth", EARTH);
72 print_planet("Mars", MARS);
73 print_planet("Jupiter", JUPITER);
74 print_planet("Saturn", SATURN);
75 print_planet("Uranus", URANUS);
76 print_planet("Neptune", NEPTUNE);
77
78 return 0;
79}
cartesian::position::HelioBarycentric< qtty::AstronomicalUnit > sun_barycentric(const JulianDate &jd)
Sun's barycentric position (EclipticMeanJ2000, AU) via VSOP87.
Definition ephemeris.hpp:26
cartesian::position::GeoBarycentric< qtty::AstronomicalUnit > earth_barycentric(const JulianDate &jd)
Earth's barycentric position (EclipticMeanJ2000, AU) via VSOP87.
Definition ephemeris.hpp:36
cartesian::position::EclipticMeanJ2000< qtty::AstronomicalUnit > earth_heliocentric(const JulianDate &jd)
Earth's heliocentric position (EclipticMeanJ2000, AU) via VSOP87.
Definition ephemeris.hpp:46
cartesian::position::MoonGeocentric< qtty::Kilometer > moon_geocentric(const JulianDate &jd)
Moon's geocentric position (EclipticMeanJ2000, km) via ELP2000.
Definition ephemeris.hpp:56
const Planet NEPTUNE
Definition bodies.hpp:137
const Planet SATURN
Definition bodies.hpp:135
const Planet MERCURY
Definition bodies.hpp:130
const Planet URANUS
Definition bodies.hpp:136
const Planet VENUS
Definition bodies.hpp:131
const Planet MARS
Definition bodies.hpp:133
const Planet JUPITER
Definition bodies.hpp:134
const Planet EARTH
Definition bodies.hpp:132
Umbrella header for the siderust C++ wrapper library.
static void print_planet(const char *name, const Planet &p)
static double norm3(const PosT &p)
double inclination_deg
Definition bodies.hpp:48
double semi_major_axis_au
Definition bodies.hpp:46
double eccentricity
Definition bodies.hpp:47
Planet data (value type, copyable).
Definition bodies.hpp:68
double radius_km
Definition bodies.hpp:70