-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR3Graph.cpp
More file actions
73 lines (61 loc) · 1.63 KB
/
R3Graph.cpp
File metadata and controls
73 lines (61 loc) · 1.63 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
#include "R3Graph.h"
bool R3Point::inCube() {
return ((0 <= x) && (x <= 1) &&
(0 <= y) && (y <= 1) &&
(0 <= z) && (z <= 1));
}
void R3Point::print() {
std::cout << x << " " << y << " " << z << std::endl;
}
InterPlane& InterPlane::operator=(const InterPlane &plane) {
this->A = plane.A;
this->B = plane.B;
this->C = plane.C;
this->D = plane.D;
this->x = plane.x;
this->y = plane.y;
this->z = plane.z;
return *this;
}
void InterPlane::set(double A, double B, double C,
double x, double y, double z) {
this->A = A;
this->B = B;
this->C = C;
D = -(A*x + B*y + C*z);
this->x = x;
this->y = y;
this->z = z;
}
double InterPlane::findT(double a, double b, double c,
double x, double y, double z) {
return -(A*x + B*y + C*z + D)/(A*a + B*b + C*c);
}
void InterPlane::findInter(R3Point *pts, int n,
double a, double b, double c,
double x, double y, double z) {
double t;
if (fabs(A*a + B*b + C*c) < 1e-16)
pts[n] = {-1, -1, -1};
else {
t = findT(a, b, c, x, y, z);
pts[n] = {x + a*t, y + b*t, z + c*t};
}
}
R3Point* InterPlane::interWithCube() {
R3Point *pts = new R3Point[12];
// search intersection points with all lines
findInter(pts, 0, 0, 1, 0, 0, 0, 0);
findInter(pts, 1, 1, 0, 0, 0, 1, 0);
findInter(pts, 2, 0, 1, 0, 1, 0, 0);
findInter(pts, 3, 1, 0, 0, 0, 0, 0);
findInter(pts, 4, 0, 0, 1, 0, 0, 0);
findInter(pts, 5, 0, 0, 1, 0, 1, 0);
findInter(pts, 6, 0, 0, 1, 1, 1, 0);
findInter(pts, 7, 0, 0, 1, 1, 0, 0);
findInter(pts, 8, 0, 1, 0, 0, 0, 1);
findInter(pts, 9, 1, 0, 0, 0, 1, 1);
findInter(pts, 10, 0, 1, 0, 1, 0, 1);
findInter(pts, 11, 1, 0, 0, 0, 0, 1);
return pts;
}