-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlane.h
90 lines (74 loc) · 2.19 KB
/
Plane.h
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
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_PLANE_H
#define PHYSICSFORMULA_PLANE_H
#include "Vector.h"
#include "Point.h"
#include <iostream>
using namespace std;
namespace rez {
template<class T>
class Plane {
// Based on the normal-point form ( n . X_ = d ) definition of a plane
// Vector3f normal;
// float d = 0;
public:
Vector3f normal;
float d = 0;
Plane() {}
Plane(Vector3f& _normal) :normal(_normal) {
normal.normalize();
}
// Make sure to calculate the _constant using normalized vector.
Plane(Vector3f& _normal, float _constant) : normal(_normal), d(_constant) {
normal.normalize();
}
Plane(Vector3f& _normal, Point3d& _point)
{
normal = _normal;
d = dotProduct(normal, _point);
}
Plane(Point3d& _p1, Point3d& _p2, Point3d& _p3)
{
Vector3f v21 = _p2 - _p1;
Vector3f v31 = _p3 - _p1;
normal = crossProduct3d(v21, v31);
normal.normalize();
d = dotProduct(normal, _p1);
}
//Eqality check
bool operator==(const Plane<T>& _other)
{
if (normal == _other.normal && isEqualD(d, _other.d))
{
return true;
}
return false;
}
//Not equal check operator
bool operator!=(const Plane<T>& _other)
{
return !(*this == _other);
}
Vector<T> getNormal() const
{
return normal;
}
float getD() const
{
return d;
}
template <typename K>
friend ostream& operator<<(ostream& os, const Plane<T>& rhs);
};
typedef Plane<float> Planef;
template<typename K>
ostream& operator<<(ostream& os, const Plane<K>& rhs)
{
os << "the normal vector is: ";
os << "<" << rhs.normal[0] << ", " << rhs.normal[1] << ", " << rhs.normal[2] << ">" << std::endl;
return os;
}
}
#endif //PHYSICSFORMULA_PLANE_H