Astro  0.0.0
A C++ library for space dynamics
Loading...
Searching...
No Matches
Utilities.hxx
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Astro project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef ASTRO_UTILITIES_HXX
14#define ASTRO_UTILITIES_HXX
15
16namespace Astro {
17
18 /*\
19 | ____
20 | | _ \ _____ _____ _ __
21 | | |_) / _ \ \ /\ / / _ \ '__|
22 | | __/ (_) \ V V / __/ |
23 | |_| \___/ \_/\_/ \___|_|
24 |
25 \*/
26
32 Real power2(Real x) {return x*x;}
33
39 Real power3(Real x) {return x*x*x;}
40
46 Real power4(Real x) {return x*x*x*x;}
47
48 /*\
49 | _ _
50 | / \ _ __ __ _| | ___
51 | / _ \ | '_ \ / _` | |/ _ \
52 | / ___ \| | | | (_| | | __/
53 | /_/ \_\_| |_|\__, |_|\___|
54 | |___/
55 \*/
56
57 static Real const PI = Real(3.141592653589793238462643383279502884197);
58 static Real const PIMUL2 = Real(6.283185307179586476925286766559005768394);
59 static Real const PIDIV2 = Real(1.570796326794896619231321691639751442098);
60 static Real const DEG2RAD = Real(0.017453292519943295769236907684886127134);
61 static Real const RAD2DEG = Real(57.29577951308232087679815481410517033240);
62
69 Real deg_to_rad(Real x) {return DEG2RAD*x;}
70
77 Real rad_to_deg(Real x) {return RAD2DEG*x;}
78
86 {
87 x = std::fmod(x, PIMUL2);
88 while (x < Real(0.0)) {x += PIMUL2;}
89 while (x > PIMUL2) {x -= PIMUL2;}
90 return x;
91 }
92
100 {
101 x = std::fmod(x, PIMUL2);
102 while (x < -PI) {x += PIMUL2;}
103 while (x > PI) {x -= PIMUL2;}
104 return x;
105 }
106
107 /*\
108 | ____ _ _
109 | | _ \‍(_)___| |_ __ _ _ __ ___ ___
110 | | | | | / __| __/ _` | '_ \ / __/ _ \
111 | | |_| | \__ \ || (_| | | | | (_| __/
112 | |____/|_|___/\__\__,_|_| |_|\___\___|
113 |
114 \*/
115
116 static Real const AU_TO_KM{1.49597870707e+08};
117 static Real const LY_TO_KM{9.4607304725808e+12};
118 static Real const PC_TO_AU{6.48e+05/PI};
119 static Real const PC_TO_KM{PC_TO_AU*AU_TO_KM};
120 static Real const AU_TO_PC{1.0/PC_TO_AU};
121 static Real const LY_TO_PC{1.0/PC_TO_AU};
122 static Real const KM_TO_PC{1.0/PC_TO_KM};
123 static Real const PC_TO_LY{1.0/LY_TO_PC};
124 static Real const KM_TO_LY{1.0/LY_TO_KM};
125 static Real const LY_TO_AU{LY_TO_KM/AU_TO_KM};
126 static Real const AU_TO_LY{1.0/LY_TO_AU};
127 static Real const KM_TO_AU{1.0/AU_TO_KM};
128
129 static Real const KM_TO_M{1000.0};
130 static Real const M_TO_KM{1.0/KM_TO_M};
131 static Real const AU_TO_M{AU_TO_KM*KM_TO_M};
132 static Real const LY_TO_M{LY_TO_KM*KM_TO_M};
133 static Real const PC_TO_M{LY_TO_KM*KM_TO_M};
134 static Real const M_TO_PC{LY_TO_KM*KM_TO_M};
135 static Real const M_TO_LY{LY_TO_KM*KM_TO_M};
136 static Real const M_TO_AU{LY_TO_KM*KM_TO_M};
137
138
139 // Time units
140 static Real const DAY_TO_SEC{86400.0};
141 static Real const SEC_TO_DAY{1.0/DAY_TO_SEC};
142
143 static Real const KG_M_SEC2_TO_KG_AU_DAY2{M_TO_AU/(SEC_TO_DAY*SEC_TO_DAY)}; // Kg * m/s^2 => Kg * UA / day^2
144
145 static Real const gravity_kg_m_s2{9.80665};
147
148
149 static Real const muSun_km3s2{1.32712440018E11}; // Km^3/s^2
150 static Real const muSun_AU3DAY2{muSun_km3s2*(KM_TO_AU*KM_TO_AU*KM_TO_AU)/(SEC_TO_DAY*SEC_TO_DAY)}; // Km^3/s^2
151//#define ASTRO_MU_SUN 1.32712440018e20
152//#define ASTRO_MU_EARTH 398600441800000.0
153//#define ASTRO_EARTH_VELOCITY 29784.6905
154//#define ASTRO_EARTH_J2 1.08262668E-03
155//#define ASTRO_EARTH_RADIUS 6378137
156 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157
158 Real AU_to_KM(Real x) {return x * AU_TO_KM;}
159
160 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161
163
164 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165
167
168 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169
171
172} // namespace Astro
173
174#endif // ASTRO_UTILITIES_HXX
The namespace for the Astro library.
Definition Astro.hh:72
static Real const DAY_TO_SEC
Definition Utilities.hxx:140
static Real const PI
Definition Utilities.hxx:57
static Real const M_TO_LY
Definition Utilities.hxx:135
Real angle_in_range(Real x)
Definition Utilities.hxx:85
Real AU_by_DAY3_to_km_by_s3(Real x)
Definition Utilities.hxx:170
static Real const AU_TO_M
Definition Utilities.hxx:131
static Real const AU_TO_PC
Definition Utilities.hxx:120
static Real const KG_M_SEC2_TO_KG_AU_DAY2
Definition Utilities.hxx:143
Real power4(Real x)
Definition Utilities.hxx:46
static Real const KM_TO_PC
Definition Utilities.hxx:122
static Real const PC_TO_AU
Definition Utilities.hxx:118
static Real const AU_TO_LY
Definition Utilities.hxx:126
static Real const RAD2DEG
Definition Utilities.hxx:61
static Real const KM_TO_M
Definition Utilities.hxx:129
static Real const AU_TO_KM
Definition Utilities.hxx:116
static Real const muSun_km3s2
Definition Utilities.hxx:149
static Real const DEG2RAD
Definition Utilities.hxx:60
static Real const KM_TO_LY
Definition Utilities.hxx:124
double Real
Definition Astro.hh:83
Real power2(Real x)
Definition Utilities.hxx:32
Real AU_by_DAY_to_km_by_s(Real x)
Definition Utilities.hxx:162
Real rad_to_deg(Real x)
Definition Utilities.hxx:77
Real AU_to_KM(Real x)
Definition Utilities.hxx:158
Real power3(Real x)
Definition Utilities.hxx:39
static Real const gravity_kg_AU_DAY2
Definition Utilities.hxx:146
static Real const PIMUL2
Definition Utilities.hxx:58
static Real const gravity_kg_m_s2
Definition Utilities.hxx:145
Real deg_to_rad(Real x)
Definition Utilities.hxx:69
static Real const muSun_AU3DAY2
Definition Utilities.hxx:150
Real angle_in_range_sym(Real x)
Definition Utilities.hxx:99
static Real const PC_TO_M
Definition Utilities.hxx:133
Real AU_by_DAY2_to_km_by_s2(Real x)
Definition Utilities.hxx:166
static Real const PIDIV2
Definition Utilities.hxx:59