siderust-cpp 0.8.0
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
01_basic_coordinates.cpp

Basic coordinate construction and type-safe coordinate operations.

// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 Vallés Puig, Ramon
#include <iostream>
using namespace siderust;
using namespace siderust::frames;
using namespace siderust::centers;
using namespace qtty::literals;
int main() {
std::cout << "=== Siderust Basic Coordinates Example ===\n\n";
std::cout << "Earth heliocentric ecliptic: " << earth << '\n';
std::cout << " distance from Sun: " << earth.distance() << "\n\n";
100000.0);
std::cout << "Moon geocentric equatorial: " << moon << '\n';
std::cout << " distance from Earth: " << moon.distance() << "\n\n";
spherical::direction::EquatorialMeanJ2000 polaris(37.95_deg, 89.26_deg);
std::cout << "Polaris direction: " << polaris << "\n\n";
auto betelgeuse_distance = qtty::LightYear(500.0).to<qtty::AstronomicalUnit>();
spherical::position::ICRS<qtty::AstronomicalUnit> betelgeuse(88.79_deg, 7.41_deg,
betelgeuse_distance);
std::cout << "Betelgeuse: " << betelgeuse << "\n\n";
spherical::direction::Horizontal zenith(0.0_deg, 90.0_deg);
std::cout << "Zenith (horizontal): " << zenith << '\n';
5000.0_km);
std::cout << "Cloud at zenith: " << cloud << "\n\n";
0.707);
std::cout << "Cartesian: " << cart_pos << '\n';
auto sph_pos = cart_pos.to_spherical();
std::cout << "Spherical: " << sph_pos << '\n';
std::cout << "Back to cartesian: " << sph_pos.to_cartesian() << "\n\n";
std::cout << "Different centers cannot be subtracted directly:\n";
std::cout << " " << helio << '\n';
std::cout << " " << geo << '\n';
auto sep = helio.distance_to(
std::cout << "Separation (same type): " << sep << "\n\n";
std::cout << "Centers: Barycentric, Heliocentric, Geocentric, Topocentric, Bodycentric\n";
std::cout << "Frames: EclipticMeanJ2000, EquatorialMeanJ2000, Horizontal, ICRS, ECEF\n";
return 0;
}
Umbrella header for the siderust C++ wrapper library.
A 3D Cartesian position, compile-time tagged by center, frame, unit.
U distance_to(const Position &other) const
spherical::Position< C, F, U > to_spherical() const
Convert this cartesian position to a spherical Position<C,F,U>.
A direction on the celestial sphere, compile-time tagged by frame.
Definition spherical.hpp:50
qtty::Degree alt() const
Definition spherical.hpp:94
qtty::Degree az() const
Definition spherical.hpp:84
auto to(const Time< TT, JD > &jd) const -> decltype(this->template to_frame< Target >(jd))
Shorthand: .to<Target>(jd) (calls to_frame).
A spherical position (direction + distance), compile-time tagged.