-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.h
207 lines (172 loc) · 6.44 KB
/
functions.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#pragma once
#include "structures.h"
#include "constants.h"
#include "myvector_operators.h"
My_vector Calculate_coordinates_periapsis(const double& latitude, const double& longitude, const double& hight, const double& e) {
double L = longitude * PI / 180;
double B = latitude * PI / 180;
double H = hight * 1'000.; // to meters
double N = major_ax / sqrt(1 - e * e * sin(B) * sin(B));
double x = (N + H) * cos(B) * cos(L);
double y = (N + H) * cos(B) * sin(L);
double z = (N + H - N * e * e) * sin(B);
return { x, y, z };
}
std::vector<double> Calculate_elliptic_coordinates(const My_vector& coord) {
/*
Àëãîðèòì âçÿò îòñþäà: ñïåöèàëüíûå ìåòîäû ïðèêëàäíîé ãåîäåçèè, À. Î. Êóïðèÿíîâ, À. Ñ. Êîð÷àãèí, Ä. À. Ìîðîçîâ. (íà ñòð 6)
*/
double x = coord.GetX();
double y = coord.GetY();
double z = coord.GetZ();
double latitude;
double longitude;
double hight;
double Q = sqrt(x * x + y * y); //the radius of the parallel
double B1 = atan(z / (Q * (1 - eccentricity * eccentricity)));
double N;
double B_next;
double B_old = B1;
double dB;
for (int i = 0; i < 5; i++) {
N = major_ax / sqrt(1 - eccentricity * eccentricity * sin(B_old) * sin(B_old));
hight = Q / cos(B_old) - N;
B_next = atan(z / (Q * (1 - N * eccentricity * eccentricity / (N + hight))));
dB = B_next * 180.0 / PI - B_old * 180.0 / PI;
B_old = B_next;
if (abs(dB) < 1e-8) break;
}
longitude = asin(y / Q) * 180.0 / PI;
latitude = B_next * 180.0 / PI;
// cout << " L = " << longitude << " B = " << latitude << " H, km = " << hight / 1000 << endl;
if (x < 0. && y > 0.) {
longitude = 180. - longitude;
}
else if (x < 0. && y < 0.) {
longitude = -180. - longitude;
}
return { longitude, latitude, hight };
}
My_vector Get_g(const My_vector& coord) {
My_vector g = coord.Normalize();
g.Reverse();
double g_number = GE / (coord.Length() * coord.Length());
return { g.GetX() * g_number, g.GetY() * g_number, g.GetZ() * g_number };
}
std::pair<My_vector, My_vector> Calculate_state_vector(struct elements_of_orbit& orb) {
/*
Àëãîðèòì âçÿò îòñþäà: Â. È. Êðûëîâ, îñíîâû òåîðèè äâèæåíèÿ èñç (÷àñòü ïåðâàÿ: íåâîçìóù¸ííîå äâèæåíèå), (íà ñòð 28)
*/
double per_arg = orb.periapsis_argument * PI / 180;
double T = orb.true_anomaly * PI / 180;
double i = orb.inclination * PI / 180;
double L = orb.ascending_long * PI / 180;
double u = T + per_arg; // latitude argument
double p = orb.orb_major_ax * (1 - orb.orb_eccentricity * orb.orb_eccentricity); // fokal parameter
double r = p / (1 + orb.orb_eccentricity * cos(T)); // radius vector
double x = r * (cos(u) * cos(L) - sin(u) * sin(L) * cos(i));
double y = r * (sin(L) * cos(u) + sin(u) * cos(L) * cos(i));
double z = r * (sin(u) * sin(i));
double Vr = sqrt(GE / p) * orb.orb_eccentricity * sin(T); // radial velocity
double V1 = sqrt(GE / p) * (1 + orb.orb_eccentricity * cos(T));
double Vx = Vr * (cos(u) * cos(L) - sin(u) * sin(L) * cos(i)) + V1 * (-cos(L) * sin(u) - sin(L) * cos(u) * cos(i));
double Vy = Vr * (sin(L) * cos(u) + sin(u) * cos(L) * cos(i)) + V1 * (-sin(L) * sin(u) + cos(L) * cos(u) * cos(i));
double Vz = Vr * (sin(u) * sin(i)) + V1 * (cos(u) * sin(i));
return { {x, y, z}, {Vx, Vy, Vz} };
}
My_vector Get_a(const My_vector& velocity, const satellite& sat, const atmosphere& atmo) {
double a1 = (sat.Cx * atmo.ro * sat.S) / (2. * sat.mass);
My_vector vel = (velocity.Length() * velocity.Length()) * velocity.Normalize();
My_vector a = vel * a1 * -1;
return a;
}
My_vector Get_thrust_a(const My_vector& coord, const My_vector& velocity, const double& thrust, const int& way) {
My_vector acc;
if (way == 1) { // ïðîòèâ äâèæåíèÿ
acc = velocity.Normalize();
acc.Reverse();
return acc * thrust;
}
else if (way == 2) { // ïî äâèæåíèþ
acc = velocity.Normalize();
return acc * thrust;
}
else if (way == 3) { // íàïðàâî îò äâèæåíèÿ (ê öåíòðó)
acc = coord.Normalize();
acc.Reverse();
return acc * thrust;
}
else if (way == 4) { // íàëåâî îò äâèæåíèÿ (îò öåíòðà)
acc = coord.Normalize();
return acc * thrust;
}
else if (way == 5) { // ââåðõ
}
else if (way == 6) { // âíèç
}
return {};
}
std::pair<My_vector, My_vector> Function(const std::pair<My_vector, My_vector>& state, double dt, const satellite& sat, const atmosphere& atmo,
const My_vector& atm_vel) {
My_vector coord = state.first;
My_vector velocity = state.second; // orbital velocity
My_vector atmo_velocity = velocity - atm_vel;
My_vector g = Get_g(coord); // acceleration of free fall
My_vector a = Get_a(atmo_velocity, sat, atmo); // acceleration of drag of atmosphere
//My_vector a = {0.,0.,0.}; // acceleration of drag of without atmosphere
if (sat.thrust_on == true) {
a = a + Get_thrust_a(coord, velocity, (sat.thrust / sat.mass), sat.thrust_way); // plus thrust acceleration
// ïëþñ ãðàâèòàöèÿ ëóíû + ñîëíöå + äàâëåíèå ñîëíöà
}
My_vector new_coord = velocity;
My_vector new_velocity = g + a;
return { new_coord, new_velocity };
}
bool Check_turns(const double& start, const double& angle, const char& direction, const bool half_turn) {
if (direction == '+') {
if (half_turn == false) {
if (angle > start) return false;
else return true;
}
else {
if (angle > start) return true;
else return false;
}
}
else {
if (half_turn == false) {
if (angle < start) return false;
else return true;
}
else {
if (angle > start) return true;
else return false;
}
}
}
std::vector<double> Calculate_keplers_elements(const My_vector& coord_, const My_vector& velocity_) {
/*
* Ñïðàâî÷íîå ðóêîâîäñòâî ïî íåáåñíîé ìåõàíèêå è àñòðîäèíàìèêå. Àáàëàêèí Â. Ê., Àêñåíîâ Å. Ï., Ãðåáåíèêîâ Å. À., Äåìèí Â. Ã., Ðÿáîâ Þ. À.
* Èçäàíèå 2-å, äîïîëíåííîå è ïåðåðàáîòàííîå. (ñòð 283)
*/
My_vector vec_mod = coord_ / velocity_;
My_vector k = (vec_mod) / vec_mod.Length();
double i = acos(k.GetZ()) * 180. / PI;
double r = coord_.Length();
double a = 1 / (2 / r - velocity_.Length() * velocity_.Length() / GE);
return { i, a };
}
double Calculate_line_velocity_rotation(const double H_, const double latitude_) {
double angle = latitude_ * PI / 180.;
double hight = 0.;
double v1 = (major_ax * minor_ax) / sqrt(minor_ax * minor_ax + major_ax * major_ax * tan(angle) * tan(angle));
double v2 = (minor_ax * minor_ax * hight) / sqrt(pow(minor_ax, 4) + pow(major_ax, 4) * tan(angle) * tan(angle));
double v = (v1 + v2) * Angular_speed_Earth;
return v;
}
My_vector Calculate_vector_velocity_rotation(const My_vector& coord_) {
const My_vector omega{ 0, 0, Angular_speed_Earth };
My_vector v = omega / coord_;
// v.Reverse();
return v;
}