-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMBB.cpp
131 lines (118 loc) · 2.12 KB
/
MBB.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
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
#include "MBB.h"
#include <math.h>
#include <cstdlib>
#include"iostream"
using namespace std;
// for test
MBB::MBB()
{
xmin = 0;
xmax = 0;
ymin = 0;
ymax = 0;
}
MBB::MBB(float val_xmin,float val_ymin,float val_xmax,float val_ymax)
{
xmin = val_xmin;
xmax = val_xmax;
ymin = val_ymin;
ymax = val_ymax;
}
bool MBB::pInBox(float x, float y) {
if (x <= xmax &&x >= xmin&&y <= ymax&&y >= ymin)
return true;
else
return false;
}
int BoxIntersect(MBB& a1, MBB& b1) {
MBB a, b;
bool swaped = false;
if (a1.xmin < b1.xmin) {
a = a1;
b = b1;
}
else if (a1.xmin == b1.xmin) {
if (a1.xmax > b1.xmax) {
a = a1;
b = b1;
}
else
{
b = a1;
a = b1;
swaped = true;
}
}
else
{
b = a1;
a = b1;
swaped = true;
}
if (b.xmin >= a.xmax)
return 0;
else
{
if (b.ymax <= a.ymin)
return 0;
else if (b.ymin >= a.ymax)
return 0;
else {
if (a.pInBox(b.xmin, b.ymin) && a.pInBox(b.xmin, b.ymax) && a.pInBox(b.xmax, b.ymin) && a.pInBox(b.xmax, b.ymax))
{
if (!swaped)
return 2;
else
return 3;
}
else
return 1;
}
}
}
/* return 0:꼇宮슥
return 1:宮슥뎃꼇관벵
return 2:a1관벵b1
return 3:b1관벵a1
*/
int MBB::intersect(MBB& b) {
return (BoxIntersect(*this, b));
}
int MBB::randomGenerateMBB(MBB& generated)
{
float minx, maxx, miny, maxy;
minx = this->xmin;
miny = this->ymin;
maxx = this->xmax;
maxy = this->ymax;
float x1, x2;
float y1, y2;
x1 = (rand() / double(RAND_MAX))*(maxx - minx) + minx;
x2 = (rand() / double(RAND_MAX))*(maxx - minx) + minx;
y1 = (rand() / double(RAND_MAX))*(maxy - miny) + miny;
y2 = (rand() / double(RAND_MAX))*(maxy - miny) + miny;
minx = x1 > x2 ? x2 : x1;
maxx = x1 > x2 ? x1 : x2;
miny = y1 > y2 ? y2 : y1;
maxy = y1 > y2 ? y1 : y2;
generated.xmin = minx;
generated.xmax = maxx;
generated.ymin = miny;
generated.ymax = maxy;
return 0;
}
/* return 0:꼇宮슥
return 1:宮슥뎃꼇관벵
return 2:this관벵b
return 3:b관벵this
*/
int MBB::printMBB() {
cout << "MBB size: " << this->GetMBBArea() << endl;
return 0;
}
float MBB::GetMBBArea(void) {
return (this->xmax - this->xmin)*(this->ymax - this->ymin)*1e6;
}
MBB::~MBB()
{
}