-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline.cpp
More file actions
38 lines (31 loc) · 1.16 KB
/
line.cpp
File metadata and controls
38 lines (31 loc) · 1.16 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
#include "line.hpp"
namespace cpp_utils {
Line::Line(Vector setPoint, Vector setDirection) : point(setPoint) {
double magnitude = setDirection.mod();
Vector normDir = (1 / magnitude) * setDirection;
if(normDir.x < 0) {
direction = -normDir;
} else {
direction = normDir;
}
};
bool Line::operator==(const Line &that) const {
if(direction == that.direction && this->isOnLine(that.point).first) {
return true;
} else {
return false;
}
};
std::pair<bool,double> Line::isOnLine(const Vector &that) const {
Vector vecDiff = that - point;
double scalarX, scalarY, scalarZ;
if(point.x == 0) {scalarX = vecDiff.x;} else {scalarX = vecDiff.x / point.x;}
if(point.y == 0) {scalarY = vecDiff.y;} else {scalarY = vecDiff.y / point.y;}
if(point.z == 0) {scalarZ = vecDiff.z;} else {scalarZ = vecDiff.z / point.z;}
if(scalarX == scalarY && scalarX == scalarZ) {
return std::pair<bool,double> (true, scalarX);
} else {
return std::pair<bool,double> (false, 0);
}
};
}