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
| #include "usg_common.h" /* cos */
| #include "graph.h"
| #include "IndirectAlg.h"
| using namespace std;
|
| int test2() {
| // IndirectAlg indirectAlg({ {{0.0, 0.0}, {1000.0, 0.0}}, {{1000.0, 0.0}, {1000.0, 1000.0}}, {{1000.0, 1000.0}, {0.0, 1000.0}}, {{0.0, 1000.0}, {0.0, 0.0}} }, 5, {1, 1});
|
| IndirectAlg indirectAlg((std::initializer_list<Point>){{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {0.0, 1000.0} }, 5, {1, 1});
|
| int i = 0;
| time_t start_time;
| srand((unsigned) time(0));
|
| double rx, ry;
| bool isRetrograde;
| Point start = {0, 0};
| Record record;
| record.id = 1;
| record.timestamp = time(0);
| record.coordinate = start;
| time(&start_time);
| while(!(isRetrograde = indirectAlg.isRetrograde(record)) ) {
| rx = ((double)(rand()%10))/100000;
| ry = ((double)(rand()%10))/100000;
|
| //std::cout << timestamp << ":" << << "isRetrograde" << isRetrograde;
| // err_msg(0, "%ld : {%f, %f} %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
| record.timestamp = time(0);
|
| //if (difftime(time(0), start_time) > 1)
| if (i > 10)
| {
| record.coordinate = {record.coordinate.x - rx , record.coordinate.y - ry};
| } else {
| record.coordinate = {record.coordinate.x + rx , record.coordinate.y + ry};
| }
|
| if (i > 100)
| break;
|
| sleep(1);
| i++;
| }
| printf("return %ld : {%f, %f} %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
| return 0;
| }
|
|
| int main() {
| test2();
|
| }
| int test()
| {
| // cout << epsilon << endl;
| // Vector3 a = new Vector3(1, 1, 1);
| // double param, result;
| // param = 0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
| // param = 60.0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
| // param = 90.0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
| // param = 100.0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
| // param = 180.0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
|
| // param = 360.0;
| // result = cos ( param * PI / 180.0 );
| // printf ("The cosine of %f degrees is %f.\n", param, result );
|
| // result = getAngle({3, 4}, {4, 3});
| // printf ("getAngle result is %f.\n", result );
|
| // const initializer_list<Point> points = { { 5.0, 5.0}, {5.0, 8.0}, {-10.0, 5.0}, {0.0, 5.0}, {10.0, 5.0}, {8.0, 5.0}, {10.0, 10.0} };
|
| // const Figure square = { "Square",
| // { {{0.0, 0.0}, {10.0, 0.0}}, {{10.0, 0.0}, {10.0, 10.0}}, {{10.0, 10.0}, {0.0, 10.0}}, {{0.0, 10.0}, {0.0, 0.0}} }
| // };
|
| // const Figure square_hole = { "Square hole",
| // { {{0.0, 0.0}, {10.0, 0.0}}, {{10.0, 0.0}, {10.0, 10.0}}, {{10.0, 10.0}, {0.0, 10.0}}, {{0.0, 10.0}, {0.0, 0.0}},
| // {{2.5, 2.5}, {7.5, 2.5}}, {{7.5, 2.5}, {7.5, 7.5}}, {{7.5, 7.5}, {2.5, 7.5}}, {{2.5, 7.5}, {2.5, 2.5}}
| // }
| // };
|
| // const Figure strange = { "Strange",
| // { {{0.0, 0.0}, {2.5, 2.5}}, {{2.5, 2.5}, {0.0, 10.0}}, {{0.0, 10.0}, {2.5, 7.5}}, {{2.5, 7.5}, {7.5, 7.5}},
| // {{7.5, 7.5}, {10.0, 10.0}}, {{10.0, 10.0}, {10.0, 0.0}}, {{10.0, 0}, {2.5, 2.5}}
| // }
| // };
|
| // const Figure exagon = { "Exagon",
| // { {{3.0, 0.0}, {7.0, 0.0}}, {{7.0, 0.0}, {10.0, 5.0}}, {{10.0, 5.0}, {7.0, 10.0}}, {{7.0, 10.0}, {3.0, 10.0}},
| // {{3.0, 10.0}, {0.0, 5.0}}, {{0.0, 5.0}, {3.0, 0.0}}
| // }
| // };
|
| // for(auto f : {square, square_hole, strange, exagon})
| // f.check(points, cout);
|
| return EXIT_SUCCESS;
| }
|
|