-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry3D.cpp
215 lines (175 loc) · 5.23 KB
/
Geometry3D.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
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
207
208
209
210
211
212
213
214
215
#include <cmath>
class Math {
public:
static const double PI;
static const double Epsilon;
static long long abs(long long val){
if (val > 0) {
return val;
} else {
return -val;
}
}
static double abs(double val) {
if (val > 0) {
return val;
} else {
return -val;
}
}
static long long min(long long arg1, long long arg2) {
if (arg1 < arg2) {
return arg1;
} else {
return arg2;
}
}
static double min(double arg1, double arg2) {
if (arg1 < arg2) {
return arg1;
} else {
return arg2;
}
}
};
const double Math::PI = 3.14159265358979323846264338327950288419716939937510;
const double Math::Epsilon = 0.000001;
class Point3DI {
private:
long long X;
long long Y;
long long Z;
public:
Point3DI() {
this->X = 0;
this->Y = 0;
this->Z = 0;
}
Point3DI(const long long X, const long long Y, const long long Z) {
this->X = X;
this->Y = Y;
this->Z = Z;
}
void setX(long long X) {
this->X = X;
}
long long getX() const {
return this->X;
}
void setY(long long Y) {
this->Y = Y;
}
long long getY() const {
return this->Y;
}
void setZ(long long Y) {
this->Z = Z;
}
long long getZ() const {
return this->Z;
}
double distanceTo(const Point3DI *arg) const {
return sqrt((double)
(this->X - arg->X) * (this->X - arg->X) +
(this->Y - arg->Y) * (this->Y - arg->Y) +
(this->Z - arg->Z) * (this->Z - arg->Z));
}
};
class Point3DD {
private:
double X;
double Y;
double Z;
public:
Point3DD() {
this->X = 0;
this->Y = 0;
this->Z = 0;
}
Point3DD(const Point3DI &arg) {
this->X = (double)arg.getX();
this->Y = (double)arg.getY();
this->Z = (double)arg.getZ();
}
Point3DD(const double X, const double Y, const double Z) {
this->X = X;
this->Y = Y;
this->Z = Z;
}
void setX(double X) {
this->X = X;
}
double getX() const {
return this->X;
}
void setY(double Y) {
this->Y = Y;
}
double getY() const {
return this->Y;
}
void setZ(double Y) {
this->Z = Z;
}
double getZ() const {
return this->Z;
}
double distanceTo(const Point3DD *arg) const {
return sqrt((double)
(this->X - arg->X) * (this->X - arg->X) +
(this->Y - arg->Y) * (this->Y - arg->Y) +
(this->Z - arg->Z) * (this->Z - arg->Z));
}
double distanceTo(const Point3DI *arg) const {
return sqrt((double)
(this->X - arg->getX()) * (this->X - arg->getX()) +
(this->Y - arg->getY()) * (this->Y - arg->getY()) +
(this->Z - arg->getZ()) * (this->Z - arg->getZ()));
}
};
class Plane3DI {
private:
long long A;
long long B;
long long C;
long long D;
double norm;
double computeNorm() {
return sqrt((double)this->A * this->A + this->B * this->B + this->C * this->C);
}
public:
Plane3DI(const Point3DI *A, const Point3DI *B, const Point3DI *C) {
this->A = A->getY() * B->getZ() - A->getZ() * B->getY() - A->getY() * C->getZ() + B->getY() * C->getZ() + A->getZ() * C->getY() - B->getZ() * C->getY();
this->B = A->getX() * B->getZ() + A->getZ() * B->getX() + A->getX() * C->getZ() - B->getX() * C->getZ() - A->getZ() * C->getX() + B->getZ() * C->getX();
this->C = A->getX() * B->getY() - A->getY() * B->getX() - A->getX() * C->getY() + B->getX() * C->getY() + A->getY() * C->getX() - B->getY() * C->getX();
this->D =-A->getX() * B->getY() * C->getZ() + A->getY() * B->getX() * C->getZ() + A->getX() * B->getZ() * C->getY() - A->getZ() * B->getX() * C->getY() - A->getY() * B->getZ() * C->getX() + A->getZ() * B->getY() * C->getX();
this->norm = this->computeNorm();
}
long long getA() const {
return this->A;
}
long long getB() const {
return this->B;
}
long long getC() const {
return this->C;
}
long long getD() const {
return this->D;
}
double distanceTo(const Point3DI *arg) const {
return Math::abs(this->A * arg->getX() + this->B * arg->getY() + this->C * arg->getZ() + this->D) / this->norm;
}
long long getPointSign(const Point3DI *arg) const {
return this->A * arg->getX() + this->B * arg->getY() + this->C * arg->getZ() + this->D;
}
double getPointSign(const Point3DD *arg) const {
return this->A * arg->getX() + this->B * arg->getY() + this->C * arg->getZ() + this->D;
}
bool contains(const Point3DI *arg) const {
return this->getPointSign(arg) == 0;
}
bool contains(const Point3DD *arg) const {
return this->getPointSign(arg) < Math::Epsilon;
}
};