-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (59 loc) · 2.11 KB
/
main.cpp
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
#include"Exampl3d.h"
int main() {
srand(time(NULL));
vector<any> container;
int n = 5 + rand() % 15;
double t = 1.0 * M_PI / 4;
for(int i = 0; i < n; i++) {
double probability = 1.0*rand() / RAND_MAX;
if(probability < 0.33) {
Circle c(1 + rand() % 10);
container.push_back(c);
}
else if((probability >= 0.33) && (probability < 0.66)) {
Ellipse el((1 + rand() % 10), (1 + rand() % 10));
container.push_back(el);
}
else {
Helixe hel((1 + rand() % 10), (1 + 1.0*rand() / RAND_MAX));
container.push_back(hel);
}
}
vector<Circle*> circls;
for(int i = 0; i < n; i++) {
if(container[i].type() == typeid(Circle)) {
circls.push_back(any_cast<Circle>(&container[i]));
cout << "Point: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Circle>(container[i]).GetPoint(t)[j] << " ";
cout << "Derivative: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Circle>(container[i]).GetFirstDerivative(t)[j] << " ";
}
else if(container[i].type() == typeid(Ellipse)) {
cout << "Point: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Ellipse>(container[i]).GetPoint(t)[j] << " ";
cout << "Derivative: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Ellipse>(container[i]).GetFirstDerivative(t)[j] << " ";
}
else if(container[i].type() == typeid(Helixe)) {
cout << "Point: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Helixe>(container[i]).GetPoint(t)[j] << " ";
cout << "Derivative: ";
for(int j = 0; j < 3; j++)
cout << any_cast<Helixe>(container[i]).GetFirstDerivative(t)[j] << " ";
}
cout << endl;
}
double max_rad = 0;
sort(circls.begin(), circls.end(), circlcomp);
double sum = .0;
#pragma omp parallel shared(circls) reduction(+: sum) num_threads(2)
#pragma omp for
for(int i = 0; i < circls.size(); i++)
sum += circls[i]->GetRadius();
cout << "Sum radius in second container: " << sum << endl;
}