Repository navigation
Expand file tree
/
Copy pathImageDisplaceLib.cpp
More file actions
162 lines (124 loc) · 5.92 KB
/
Copy pathImageDisplaceLib.cpp
File metadata and controls
162 lines (124 loc) · 5.92 KB
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
#include "ImageDisplaceLib.h"
double mks_to_metres(double angle){
double metres;
metres = (angle * full_H * pc) / mks;
return metres;
}
double metres_to_mks(double metres){
double angle;
angle = (metres * mks) / (full_H * pc);
return angle;
}
void print(std::vector<double>& lst, bool new_line, bool error_stream) {
for (double x : lst) {
if (error_stream == 0) std::cout << x << " ";
if (error_stream == 1) std::cerr << x << " ";
}
if (new_line) {
if (error_stream == 0) std::cout << std::endl;
if (error_stream == 1) std::cerr << std::endl;
}
}
std::pair<double, double> get_displace_of_ray_by_single_star(std::vector<double> &star, std::vector<double> &ray) {
// In vector star distances given in pc, mass in m0. Ray coord given in meters
double temp_x = ray[0], temp_y = ray[1];
double distance, alpha;
std::pair<double, double> displace;
temp_x *= (star[2] / full_H);
temp_y *= (star[2] / full_H);
temp_x -= star[0] * pc;
temp_y -= star[1] * pc;
distance = sqrt(temp_x * temp_x + temp_y * temp_y);
if (distance < 1) {
std::cerr << "WARNING: distance was less then 1 meter, it has been set to 100pc." << std::endl;
close_stars_counter++;
std::cerr << "Ray and star were ";
print(ray, false, true);
print(star, true, true);
distance = 100 * pc;
}
alpha = (4 * G * star[3] * m0) / (c * c * distance); // star[3] это масса если че -> альфа безразмерная, в СИ (без лишних десяток в степени)
double multiplier;
multiplier = (alpha * full_H * pc) / distance;
displace.first = temp_x * multiplier;
displace.second = temp_y * multiplier;
// displace содержит координаты смещенного луча на верхней плоскости
return displace;
}
std::pair<double, double> get_full_displace(std::vector<std::vector<double>> &stars, std::vector<double> &ray){
std::pair<double, double> temp, displace = {0, 0};
for (auto & star : stars){
temp = get_displace_of_ray_by_single_star(star, ray);
displace.first += temp.first;
displace.second += temp.second;
}
return displace; // в метрах, на верхней плоскости
}
double get_correlation_of_values(std::vector<double> &v1, std::vector<double> &v2){ // i dont use that anymore
if (v1.size() != v2.size()) return 0;
auto n = v1.size();
double mean_value_v1 = 0, mean_value_v2 = 0;
double covariance = 0, deviation1 = 0, deviation2 = 0;
for (int i = 0; i < n; i++){
mean_value_v1 += v1[i];
mean_value_v2 += v2[i];
}
mean_value_v1 /= n;
mean_value_v2 /= n; // получаем средние двух векторов
for (int i = 0; i < n; i++){
covariance += (v1[i] - mean_value_v1) * (v2[i] - mean_value_v2);
deviation1 += (v1[i] - mean_value_v1) * (v1[i] - mean_value_v1);
deviation2 += (v2[i] - mean_value_v2) * (v2[i] - mean_value_v2); // посчитали cov и dev для обоих векторов
}
std::cout << "cov dev1 dev2:" << covariance << " " << deviation1 << " " << deviation2 << std::endl;
if (deviation1 * deviation2 == 0) {
std::cout << "At least one deviation is zero!" << std::endl;
return 1;
}
return (covariance / sqrt(deviation1 * deviation2));
}
std::vector<std::vector<double>> get_random_3d_velocity(long amount, double v_min, double v_max){
std::vector<std::vector<double>> velocity(amount);
std::vector<double> temp(3, 0);
std::mt19937_64 gen(time(nullptr));
std::uniform_real_distribution<> urd(-1, 1);
std::uniform_real_distribution<> urd_max(v_min, v_max);
double Vsum, V;
for (long i = 0; i < amount; i++){
temp[0] = urd(gen);
temp[1] = urd(gen);
temp[2] = urd(gen);
Vsum = 1000 * urd_max(gen);
V = sqrt(temp[0] * temp[0] + temp[1] * temp[1] + temp[2] * temp[2]);
temp[0] = temp[0] * Vsum / V;
temp[1] = temp[1] * Vsum / V;
temp[2] = temp[2] * Vsum / V;
velocity[i] = temp;
}
return velocity;
}
std::vector<std::vector<double>> get_stars_set(std::string path, long n, bool generate_new){
std::cout << "Getting stars' data..." << std::endl;
if (generate_new){
// Нужно разобраться с тонкостями работы system(command) и оптимизировать питоний код, может перенести сюда
// По итогу этого ифа нужно оставлять в path путь на файл с звездами, в идеале еще создавать переменную
// с их количеством, но лучше это делать не как на момент написания коммента - через отдельный файлик
// Можно попробовать сразу звезды передавать, но что-то я сомневаюсь в простоте реализации такого варианта
// system("python C:\\RW\\star_gen.py"); - эта штука работает, но вроде как адрес должен быть const
}
std::vector<double> single_star(5, 1); // последний элемент - тип - 1=disk, 2=flat, 0=corona
char population_type;
std::vector<std::vector<double>> stars(n);
std::ifstream fin(path);
for (int i = 0; i < n; i++){
for (int j = 0; j < 4; j++) fin >> single_star[j];
fin >> population_type;
if (population_type == 'd') single_star[4] = 1;
if (population_type == 'f') single_star[4] = 2;
if (population_type == 'c') single_star[4] = 0;
stars[i] = single_star;
if (i % 1000000 == 0) std::cout << "Has been loaded " << i << " stars of " << n << std::endl;
}
fin.close();
return stars;
}