This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.hpp
61 lines (49 loc) · 1.87 KB
/
calc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __CALC_H_
#define __CALC_H_
#include <units/physical/si/derived/speed.h>
#include <units/concepts.h>
#include <units/math.h> // NOLINT(modernize-deprecated-headers)
using namespace units;
using namespace units::physical;
// coherent unit must apply to the system rules (in this case SI)
struct metre_cub_per_second_sq : unit<metre_cub_per_second_sq> {
};
// new derived dimensions
struct dim_gravitational_parameter
: derived_dimension<dim_gravitational_parameter, metre_cub_per_second_sq,
exponent<si::dim_length, 3>, exponent<si::dim_time, -2>> {
};
// a quantity of our dimension
template<UnitOf <dim_gravitational_parameter> U, QuantityValue Rep = double>
using gravitational_parameter = quantity<dim_gravitational_parameter, U, Rep>;
// a concept matching the above quantity
template<typename T>
concept GravitationalParameter = QuantityOf<T, dim_gravitational_parameter>;
class HohmannTransfer {
const gravitational_parameter<metre_cub_per_second_sq> mu_1;
const gravitational_parameter<metre_cub_per_second_sq> mu_2;
Speed auto dVPer() const {
return units::sqrt(mu_1 / r_1) *
(units::sqrt((2 * r_2 / r_1) / (1 + r_2 / r_1)) - 1);
}
Speed auto dVApo() const {
return units::sqrt(mu_1 / r_2) *
(1 - units::sqrt(2 / (1 + r_2 / r_1)));
}
public:
const si::length<si::metre> r_1;
const si::length<si::metre> r_2;
const si::speed<si::metre_per_second> dV_A;
const si::speed<si::metre_per_second> dV_P;
const si::speed<si::metre_per_second> dV_T;
HohmannTransfer(GravitationalParameter auto mu_1, GravitationalParameter auto mu_2, Length auto r_1,
Length auto r_2) :
mu_1(mu_1),
mu_2(mu_2),
r_1(r_1),
r_2(r_2),
dV_A(dVApo()),
dV_P(dVPer()),
dV_T(dV_A + dV_P) {};
};
#endif