Astro  0.0.0
A C++ library for space dynamics
Loading...
Searching...
No Matches
Astro.hh
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 GNU GPLv3. *
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 INCLUDE_ASTRO_HH
14#define INCLUDE_ASTRO_HH
15
16// C++ standard libraries
17#include <iostream>
18#include <tuple>
19#include <string>
20#include <cmath>
21
22// Eigen library
23#include <Eigen/Dense>
24#include <Eigen/Geometry>
25
26// AutoDiff library
27//#include <autodiff/forward/real.hpp>
28//#include <autodiff/forward/real/eigen.hpp>
29
30// Print Astro errors
31#ifndef ASTRO_ERROR
32#define ASTRO_ERROR(MSG) \
33 { \
34 std::ostringstream os; \
35 os << MSG; \
36 throw std::runtime_error(os.str()); \
37 }
38#endif
39
40
41// Assert for Astro
42#ifndef ASTRO_ASSERT
43#define ASTRO_ASSERT(COND, MSG) \
44 if (!(COND)) \
45 { \
46 ASTRO_ERROR(MSG); \
47 }
48#endif
49
50// Warning for Astro
51#ifndef ASTRO_WARNING
52#define ASTRO_WARNING(MSG) \
53 { \
54 std::cout << MSG << std::endl; \
55 }
56#endif
57
58// Warning assert for Astro
59#ifndef ASTRO_ASSERT_WARNING
60#define ASTRO_ASSERT_WARNING(COND, MSG) \
61 if (!(COND)) \
62 { \
63 ASTRO_WARNING(MSG); \
64 }
65#endif
66
72namespace Astro
73{
74
75 /*\
76 | _ _ _
77 | / \ | (_) __ _ ___ ___ ___
78 | / _ \ | | |/ _` / __|/ _ \/ __|
79 | / ___ \| | | (_| \__ \ __/\__ \
80 | /_/ \_\_|_|\__,_|___/\___||___/
81 |
82 \*/
83
84 using Real = double;
85 using Integer = int;
86
87 using Vector0 = Eigen::Vector<Real, 0>;
88 using Matrix0 = Eigen::Matrix<Real, 0, 0>;
89 using Vector1 = Eigen::Vector<Real, 1>;
90 using Matrix1 = Eigen::Matrix<Real, 1, 1>;
91 using Vector2 = Eigen::Vector<Real, 2>;
92 using Matrix2 = Eigen::Matrix<Real, 2, 2>;
93 using Vector3 = Eigen::Vector<Real, 3>;
94 using Matrix3 = Eigen::Matrix<Real, 3, 3>;
95 using Vector4 = Eigen::Vector<Real, 4>;
96 using Matrix4 = Eigen::Matrix<Real, 4, 4>;
97 using Vector5 = Eigen::Vector<Real, 5>;
98 using Matrix5 = Eigen::Matrix<Real, 5, 5>;
99 using Vector6 = Eigen::Vector<Real, 6>;
100 using Matrix6 = Eigen::Matrix<Real, 6, 6>;
101 using Vector7 = Eigen::Vector<Real, 7>;
102 using Matrix7 = Eigen::Matrix<Real, 7, 7>;
103 using Vector8 = Eigen::Vector<Real, 8>;
104 using Matrix8 = Eigen::Matrix<Real, 8, 8>;
105 using Vector9 = Eigen::Vector<Real, 9>;
106 using Matrix9 = Eigen::Matrix<Real, 9, 9>;
107
108 using VectorX = Eigen::Vector<Real, Eigen::Dynamic>;
109 using MatrixX = Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic>;
110
111 using Rotation = Eigen::Matrix<Real, 3, 3>;
112 using Quaternion = Eigen::Quaternion<Real>;
113 using Scale = Eigen::DiagonalMatrix<Real, 3>;
114 using Translate = Eigen::Translation<Real, 3>;
115 using AngleAxis = Eigen::AngleAxis<Real>;
116 using Affine = Eigen::Transform<Real, 3, Eigen::Affine>;
117
118 /*\
119 | ____ _ _
120 | / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
121 | | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
122 | | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
123 | \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
124 |
125 \*/
126
127 static Real const EPSILON = std::numeric_limits<Real>::epsilon();
128 static Real const SQRT_EPSILON = std::sqrt(EPSILON);
129 static Real const CBRT_EPSILON = std::cbrt(EPSILON);
130 static Real const EPSILON_HIGH = Real(1.0e-12);
131 static Real const EPSILON_MEDIUM = Real(1.0e-10);
132 static Real const EPSILON_LOW = Real(1.0e-08);
133 static Real const INFTY = std::numeric_limits<Real>::infinity();
134 static Real const QUIET_NAN = std::numeric_limits<Real>::quiet_NaN();
135
136 static Vector1 const NAN_VEC1 = Vector1::Constant(QUIET_NAN);
137 static Matrix1 const NAN_MAT1 = Matrix1::Constant(QUIET_NAN);
138 static Vector1 const ZEROS_VEC1 = Vector1::Zero();
139 static Matrix1 const ZEROS_MAT1 = Matrix1::Zero();
140 static Vector1 const ONES_VEC1 = Vector1::Ones();
141 static Matrix1 const ONES_MAT1 = Matrix1::Ones();
142 static Matrix1 const IDENTITY_MAT1 = Matrix1::Identity();
143
144 static Vector2 const NAN_VEC2 = Vector2::Constant(QUIET_NAN);
145 static Matrix2 const NAN_MAT2 = Matrix2::Constant(QUIET_NAN);
146 static Vector2 const ZEROS_VEC2 = Vector2::Zero();
147 static Matrix2 const ZEROS_MAT2 = Matrix2::Zero();
148 static Vector2 const ONES_VEC2 = Vector2::Ones();
149 static Matrix2 const ONES_MAT2 = Matrix2::Ones();
150 static Matrix2 const IDENTITY_MAT2 = Matrix2::Identity();
151
152 static Vector3 const NAN_VEC3 = Vector3::Constant(QUIET_NAN);
153 static Matrix3 const NAN_MAT3 = Matrix3::Constant(QUIET_NAN);
154 static Vector3 const ZEROS_VEC3 = Vector3::Zero();
155 static Matrix3 const ZEROS_MAT3 = Matrix3::Zero();
156 static Vector3 const ONES_VEC3 = Vector3::Ones();
157 static Matrix3 const ONES_MAT3 = Matrix3::Ones();
158 static Matrix3 const IDENTITY_MAT3 = Matrix3::Identity();
159
160 static Vector4 const NAN_VEC4 = Vector4::Constant(QUIET_NAN);
161 static Matrix4 const NAN_MAT4 = Matrix4::Constant(QUIET_NAN);
162 static Vector4 const ZEROS_VEC4 = Vector4::Zero();
163 static Matrix4 const ZEROS_MAT4 = Matrix4::Zero();
164 static Vector4 const ONES_VEC4 = Vector4::Ones();
165 static Matrix4 const ONES_MAT4 = Matrix4::Ones();
166 static Matrix4 const IDENTITY_MAT4 = Matrix4::Identity();
167
168 static Vector5 const NAN_VEC5 = Vector5::Constant(QUIET_NAN);
169 static Matrix5 const NAN_MAT5 = Matrix5::Constant(QUIET_NAN);
170 static Vector5 const ZEROS_VEC5 = Vector5::Zero();
171 static Matrix5 const ZEROS_MAT5 = Matrix5::Zero();
172 static Vector5 const ONES_VEC5 = Vector5::Ones();
173 static Matrix5 const ONES_MAT5 = Matrix5::Ones();
174 static Matrix5 const IDENTITY_MAT5 = Matrix5::Identity();
175
176 static Vector6 const NAN_VEC6 = Vector6::Constant(QUIET_NAN);
177 static Matrix6 const NAN_MAT6 = Matrix6::Constant(QUIET_NAN);
178 static Vector6 const ZEROS_VEC6 = Vector6::Zero();
179 static Matrix6 const ZEROS_MAT6 = Matrix6::Zero();
180 static Vector6 const ONES_VEC6 = Vector6::Ones();
181 static Matrix6 const ONES_MAT6 = Matrix6::Ones();
182 static Matrix6 const IDENTITY_MAT6 = Matrix6::Identity();
183
184 static Vector7 const NAN_VEC7 = Vector7::Constant(QUIET_NAN);
185 static Matrix7 const NAN_MAT7 = Matrix7::Constant(QUIET_NAN);
186 static Vector7 const ZEROS_VEC7 = Vector7::Zero();
187 static Matrix7 const ZEROS_MAT7 = Matrix7::Zero();
188 static Vector7 const ONES_VEC7 = Vector7::Ones();
189 static Matrix7 const ONES_MAT7 = Matrix7::Ones();
190 static Matrix7 const IDENTITY_MAT7 = Matrix7::Identity();
191
192 static Vector8 const NAN_VEC8 = Vector8::Constant(QUIET_NAN);
193 static Matrix8 const NAN_MAT8 = Matrix8::Constant(QUIET_NAN);
194 static Vector8 const ZEROS_VEC8 = Vector8::Zero();
195 static Matrix8 const ZEROS_MAT8 = Matrix8::Zero();
196 static Vector8 const ONES_VEC8 = Vector8::Ones();
197 static Matrix8 const ONES_MAT8 = Matrix8::Ones();
198 static Matrix8 const IDENTITY_MAT8 = Matrix8::Identity();
199
200 static Vector9 const NAN_VEC9 = Vector9::Constant(QUIET_NAN);
201 static Matrix9 const NAN_MAT9 = Matrix9::Constant(QUIET_NAN);
202 static Vector9 const ZEROS_VEC9 = Vector9::Zero();
203 static Matrix9 const ZEROS_MAT9 = Matrix9::Zero();
204 static Vector9 const ONES_VEC9 = Vector9::Ones();
205 static Matrix9 const ONES_MAT9 = Matrix9::Ones();
206 static Matrix9 const IDENTITY_MAT9 = Matrix9::Identity();
207
208 /*\
209 | ___ __
210 | |_ _|_ __ / _| ___
211 | | || '_ \| |_ / _ \
212 | | || | | | _| (_) |
213 | |___|_| |_|_| \___/
214 |
215 \*/
216
221 std::string Info() {
222 std::ostringstream os;
223 os
224 << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << std::endl
225 << "* Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *" << std::endl
226 << "* *" << std::endl
227 << "* The Astro project is distributed under the BSD 2-Clause License. *" << std::endl
228 << "* *" << std::endl
229 << "* Davide Stocco Enrico Bertolazzi *" << std::endl
230 << "* University of Trento University of Trento *" << std::endl
231 << "* e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *" << std::endl
232 << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << std::endl;
233 return os.str();
234 }
235
240 void Info(std::ostream &os) {os << Info();}
241
242} // namespace Astro
243
244#endif // INCLUDE_ASTRO_HH
The namespace for the Astro library.
Definition Astro.hh:73
static Vector3 const ZEROS_VEC3
Definition Astro.hh:154
static Vector9 const NAN_VEC9
Definition Astro.hh:200
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition Astro.hh:109
static Vector8 const NAN_VEC8
Definition Astro.hh:192
static Vector7 const NAN_VEC7
Definition Astro.hh:184
static Matrix2 const IDENTITY_MAT2
Definition Astro.hh:150
static Vector5 const ONES_VEC5
Definition Astro.hh:172
static Matrix2 const ONES_MAT2
Definition Astro.hh:149
Eigen::Matrix< Real, 3, 3 > Matrix3
Definition Astro.hh:94
Eigen::Quaternion< Real > Quaternion
Definition Astro.hh:112
static Real const EPSILON_HIGH
Definition Astro.hh:130
static Vector6 const ZEROS_VEC6
Definition Astro.hh:178
static Matrix1 const ZEROS_MAT1
Definition Astro.hh:139
Eigen::Matrix< Real, 0, 0 > Matrix0
Definition Astro.hh:88
static Matrix8 const NAN_MAT8
Definition Astro.hh:193
Eigen::Matrix< Real, 7, 7 > Matrix7
Definition Astro.hh:102
static Vector9 const ONES_VEC9
Definition Astro.hh:204
int Integer
Definition Astro.hh:85
static Matrix4 const ZEROS_MAT4
Definition Astro.hh:163
Eigen::Vector< Real, 5 > Vector5
Definition Astro.hh:97
static Vector1 const ZEROS_VEC1
Definition Astro.hh:138
static Matrix6 const NAN_MAT6
Definition Astro.hh:177
static Real const EPSILON
Definition Astro.hh:127
Eigen::Transform< Real, 3, Eigen::Affine > Affine
Definition Astro.hh:116
static Matrix7 const NAN_MAT7
Definition Astro.hh:185
static Vector4 const ONES_VEC4
Definition Astro.hh:164
static Real const CBRT_EPSILON
Definition Astro.hh:129
static Vector9 const ZEROS_VEC9
Definition Astro.hh:202
static Vector6 const ONES_VEC6
Definition Astro.hh:180
Eigen::AngleAxis< Real > AngleAxis
Definition Astro.hh:115
static Vector3 const NAN_VEC3
Definition Astro.hh:152
Eigen::Vector< Real, 0 > Vector0
Definition Astro.hh:87
Eigen::Matrix< Real, 3, 3 > Rotation
Definition Astro.hh:111
static Matrix7 const ZEROS_MAT7
Definition Astro.hh:187
static Matrix6 const ONES_MAT6
Definition Astro.hh:181
static Real const SQRT_EPSILON
Definition Astro.hh:128
static Matrix1 const IDENTITY_MAT1
Definition Astro.hh:142
static Vector5 const ZEROS_VEC5
Definition Astro.hh:170
static Real const EPSILON_LOW
Definition Astro.hh:132
static Matrix3 const NAN_MAT3
Definition Astro.hh:153
static Real const QUIET_NAN
Definition Astro.hh:134
static Matrix4 const ONES_MAT4
Definition Astro.hh:165
static Matrix9 const ZEROS_MAT9
Definition Astro.hh:203
static Matrix1 const ONES_MAT1
Definition Astro.hh:141
static Vector4 const ZEROS_VEC4
Definition Astro.hh:162
Eigen::Vector< Real, 6 > Vector6
Definition Astro.hh:99
static Matrix8 const ZEROS_MAT8
Definition Astro.hh:195
static Matrix3 const ZEROS_MAT3
Definition Astro.hh:155
static Matrix2 const ZEROS_MAT2
Definition Astro.hh:147
static Vector4 const NAN_VEC4
Definition Astro.hh:160
Eigen::Vector< Real, 1 > Vector1
Definition Astro.hh:89
static Matrix4 const NAN_MAT4
Definition Astro.hh:161
Eigen::Vector< Real, 4 > Vector4
Definition Astro.hh:95
Eigen::Matrix< Real, 1, 1 > Matrix1
Definition Astro.hh:90
static Matrix7 const ONES_MAT7
Definition Astro.hh:189
static Matrix5 const IDENTITY_MAT5
Definition Astro.hh:174
double Real
Definition Astro.hh:84
static Matrix9 const ONES_MAT9
Definition Astro.hh:205
Eigen::Vector< Real, 9 > Vector9
Definition Astro.hh:105
Eigen::Matrix< Real, 6, 6 > Matrix6
Definition Astro.hh:100
Eigen::Matrix< Real, 5, 5 > Matrix5
Definition Astro.hh:98
Eigen::Vector< Real, 2 > Vector2
Definition Astro.hh:91
static Matrix3 const ONES_MAT3
Definition Astro.hh:157
static Vector8 const ONES_VEC8
Definition Astro.hh:196
static Vector2 const ONES_VEC2
Definition Astro.hh:148
static Matrix5 const ONES_MAT5
Definition Astro.hh:173
static Matrix9 const IDENTITY_MAT9
Definition Astro.hh:206
static Vector8 const ZEROS_VEC8
Definition Astro.hh:194
static Vector1 const NAN_VEC1
Definition Astro.hh:136
static Vector5 const NAN_VEC5
Definition Astro.hh:168
Eigen::Vector< Real, 3 > Vector3
Definition Astro.hh:93
Eigen::Vector< Real, 8 > Vector8
Definition Astro.hh:103
static Matrix5 const NAN_MAT5
Definition Astro.hh:169
static Matrix9 const NAN_MAT9
Definition Astro.hh:201
static Vector6 const NAN_VEC6
Definition Astro.hh:176
Eigen::DiagonalMatrix< Real, 3 > Scale
Definition Astro.hh:113
static Vector7 const ONES_VEC7
Definition Astro.hh:188
static Real const INFTY
Definition Astro.hh:133
static Vector1 const ONES_VEC1
Definition Astro.hh:140
static Matrix8 const IDENTITY_MAT8
Definition Astro.hh:198
static Matrix2 const NAN_MAT2
Definition Astro.hh:145
static Matrix6 const IDENTITY_MAT6
Definition Astro.hh:182
static Matrix8 const ONES_MAT8
Definition Astro.hh:197
Eigen::Matrix< Real, 8, 8 > Matrix8
Definition Astro.hh:104
static Vector2 const NAN_VEC2
Definition Astro.hh:144
static Vector3 const ONES_VEC3
Definition Astro.hh:156
static Real const EPSILON_MEDIUM
Definition Astro.hh:131
static Matrix4 const IDENTITY_MAT4
Definition Astro.hh:166
static Matrix5 const ZEROS_MAT5
Definition Astro.hh:171
Eigen::Matrix< Real, 2, 2 > Matrix2
Definition Astro.hh:92
Eigen::Vector< Real, Eigen::Dynamic > VectorX
Definition Astro.hh:108
static Matrix3 const IDENTITY_MAT3
Definition Astro.hh:158
static Vector7 const ZEROS_VEC7
Definition Astro.hh:186
Eigen::Matrix< Real, 4, 4 > Matrix4
Definition Astro.hh:96
static Matrix6 const ZEROS_MAT6
Definition Astro.hh:179
Eigen::Matrix< Real, 9, 9 > Matrix9
Definition Astro.hh:106
Eigen::Translation< Real, 3 > Translate
Definition Astro.hh:114
static Matrix7 const IDENTITY_MAT7
Definition Astro.hh:190
static Matrix1 const NAN_MAT1
Definition Astro.hh:137
static Vector2 const ZEROS_VEC2
Definition Astro.hh:146
std::string Info()
Definition Astro.hh:221
Eigen::Vector< Real, 7 > Vector7
Definition Astro.hh:101