ActiveLib
Loading...
Searching...
No Matches
Plane.h
1
6#ifndef ACTIVE_GEOMETRY_PLANE
7#define ACTIVE_GEOMETRY_PLANE
8
9#include "Active/Geometry/Point.h"
10#include "Active/Geometry/Line.h"
11#include "Active/Geometry/XPoint.h"
12#include "Active/Geometry/Vector3.h"
13
14namespace active::geometry {
15
16 class Box;
17 class Matrix3x3;
18 class Matrix4x4;
19
21 class Plane {
22 public:
23
24 // MARK: - Types
25
27 using Unique = std::unique_ptr<Plane>;
29 using Shared = std::shared_ptr<Plane>;
31 using Option = std::optional<Plane>;
32
33 // MARK: - Factory functions
34
41 static Option create(double offset, const Vector3& norm);
48 static Option create(const Point& point, const Vector3& norm);
56 static Option create(const Point& p1, const Point& p2, const Point& p3);
57
58 // MARK: - Constructors
59
63 Plane();
68 Plane(const Vector3& norm);
69
70 // MARK: - Operators
71
77 virtual Plane operator+ (const Point& offset);
83 virtual Plane& operator+= (const Point& offset);
89 virtual Plane operator* (const double& mult) const;
95 virtual Plane operator* (const Matrix3x3& matrix) const;
101 virtual Plane operator* (const Matrix4x4& matrix) const;
107 virtual Plane& operator*= (const double& mult);
113 virtual Plane& operator*= (const Matrix3x3& matrix);
119 virtual Plane& operator*= (const Matrix4x4& matrix);
120
121 // MARK: - Functions (const)
122
127 const Vector3& getNormal() const;
132 double getOffset() const;
139 Position positionOf(const Point& ref, double prec = math::eps) const;
145 Point closestPointTo(const Point& ref) const;
151 double lengthTo(const Point& ref) const;
157 double heightAt(const Point& ref, double prec = math::eps) const;
164 XPoint::Option intersectionWith(const Line& ref, double prec = math::eps) const;
171 Line::Option intersectionWith(const Plane& ref, double prec = math::eps) const;
178 Point::Option intersectionWith(const Plane& ref1, const Plane& ref2) const;
185 bool isParallelTo(const Plane& ref, double prec = math::eps) const;
192 bool cutsThrough(const Box& ref, double prec = math::eps) const;
193
194 // MARK: - Functions (mutating)
195
201 bool setNormal(const Vector3& vect);
206 void setOffset(double offset) { m_offset = offset; }
207
208 private:
214 Plane(double offset, const Vector3& norm);
220 Plane(const Point& point, const Vector3& norm);
227 Plane(const Point& p1, const Point& p2, const Point& p3);
228
229 double m_offset;
230 Vector3 m_normal;
231 };
232
233}
234
235#endif //ACTIVE_GEOMETRY_PLANE
Definition Box.h:19
Class to represent a line.
Definition Line.h:21
std::optional< Line > Option
Optional.
Definition Line.h:31
A 3x3 matrix class.
Definition Matrix3x3.h:16
A 4x4 matrix class.
Definition Matrix4x4.h:14
Class to represent a plane.
Definition Plane.h:21
virtual Plane operator*(const double &mult) const
Definition Plane.cpp:160
bool cutsThrough(const Box &ref, double prec=math::eps) const
Definition Plane.cpp:375
virtual Plane & operator*=(const double &mult)
Definition Plane.cpp:196
virtual Plane & operator+=(const Point &offset)
Definition Plane.cpp:146
std::optional< Plane > Option
Optional.
Definition Plane.h:31
double getOffset() const
Definition Plane.cpp:122
bool isParallelTo(const Plane &ref, double prec=math::eps) const
Definition Plane.cpp:362
double lengthTo(const Point &ref) const
Definition Plane.cpp:276
virtual Plane operator+(const Point &offset)
Definition Plane.cpp:134
std::shared_ptr< Plane > Shared
Shared pointer.
Definition Plane.h:29
double heightAt(const Point &ref, double prec=math::eps) const
Definition Plane.cpp:288
bool setNormal(const Vector3 &vect)
Definition Plane.cpp:411
const Vector3 & getNormal() const
Definition Plane.cpp:112
Point::Option intersectionWith(const Plane &ref1, const Plane &ref2) const
void setOffset(double offset)
Definition Plane.h:206
Plane()
Definition Plane.cpp:67
Point closestPointTo(const Point &ref) const
Definition Plane.cpp:259
XPoint::Option intersectionWith(const Line &ref, double prec=math::eps) const
Definition Plane.cpp:303
static Option create(double offset, const Vector3 &norm)
Definition Plane.cpp:28
std::unique_ptr< Plane > Unique
Unique pointer.
Definition Plane.h:27
Position positionOf(const Point &ref, double prec=math::eps) const
Definition Plane.cpp:242
Definition Point.h:36
std::optional< Point > Option
Optional.
Definition Point.h:48
A 1x3 vector class.
Definition Vector3.h:20
std::optional< XPoint > Option
Optional.
Definition XPoint.h:41
Definition Anchor2D.h:11
Position
Relative spatial position.
Definition Position.h:12
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22