ActiveLib
Loading...
Searching...
No Matches
Line.h
1
6#ifndef ACTIVE_GEOMETRY_LINE
7#define ACTIVE_GEOMETRY_LINE
8
9
10#include <memory>
11
12#include "Active/Geometry/XPoint.h"
13#include "Active/Utility/MathFunctions.h"
14
15namespace active::geometry {
16
17 class Matrix3x3;
18 class XList;
19
21 class Line {
22 public:
23
24 // MARK: - Types
25
27 using Unique = std::unique_ptr<Line>;
29 using Shared = std::shared_ptr<Line>;
31 using Option = std::optional<Line>;
32
33 // MARK: - Constructors
34
40 Line(const Point& origin, const Point& end) : origin(origin), end(end) {}
47 Line(const Point& origin, double rad, double azim) : origin(origin), end(origin) { end.movePolar(rad, azim); }
48
49 // MARK: - Variables
50
55
56 // MARK: - Operators
57
63 bool operator== (const Line& ref) const { return isEqual3D(ref); }
69 bool operator!= (const Line& ref) const { return !isEqual3D(ref); }
75 Line operator+ (const Point& offset) const;
81 Line& operator+= (const Point& offset);
87 Line operator- (const Point& offset) const;
93 Line& operator-= (const Point& offset);
99 Line operator* (double scale) const;
105 Line& operator*= (double scale);
111 Line operator* (const Matrix3x3& matrix) const;
117 Line& operator*= (const Matrix3x3& matrix);
118
119 // MARK: - Functions (const)
120
127 bool isEqual2D(const Line& ref, double prec = math::eps) const;
134 bool isEqual3D(const Line& ref, double prec = math::eps) const;
138 double length2D() const;
143 double length3D() const;
148 double azimuthAngle() const;
153 double altitudeAngle() const;
159 double angleTo(const Line& ref) const;
164 Point midpoint() const;
170 double heightAt(const Point& ref) const;
176 bool isColinearTo2D(const Line& ref, double prec = math::eps) const;
182 bool isColinearTo3D(const Line& ref, double prec = math::eps) const;
188 bool isParallelTo2D(const Line& ref, double prec = math::eps) const;
194 bool isParallelTo3D(const Line& ref, double prec = math::eps) const;
200 Point closestPointTo2D(const Point& ref, double prec = math::eps) const;
206 Point closestPointTo3D(const Point& ref, double prec = math::eps) const;
212 Point closestPointAlong2D(const Point& ref, double prec = math::eps) const;
218 Point closestPointAlong3D(const Point& ref, double prec = math::eps) const;
225 XPoint::Option intersectionWith2D(const Line& ref , double prec = math::eps) const;
233 vertex_index intersectionWith2D(const Line& ref, XList& inter, double prec = math::eps) const;
241 vertex_index intersectionWith3D(const Line& ref, XList& inter, double prec = math::eps) const;
248 Position positionOf2D(const Point& ref, double prec = math::eps) const;
255 Position positionOf3D(const Point& ref, double prec = math::eps) const;
261 bool encloses2D(const Point& ref, double prec) const;
267 bool encloses3D(const Point& ref, double prec) const;
273 double angleTo2D(const Line& ref) const;
274
275 // MARK: - Functions (mutating)
276
281 void extend(double len);
288 void movePolar(double len, double azim, double alt);
294 void movePolar(double len, double angle);
298 void flip();
299 };
300
301}
302
303#endif //ACTIVE_GEOMETRY_LINE
Class to represent a line.
Definition Line.h:21
bool isColinearTo3D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:540
Point end
The line end.
Definition Line.h:54
Point midpoint() const
Definition Line.cpp:212
bool encloses2D(const Point &ref, double prec) const
Definition Line.cpp:500
bool operator!=(const Line &ref) const
Definition Line.h:69
bool isColinearTo2D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:526
double length2D() const
Definition Line.cpp:160
bool isParallelTo2D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:467
double angleTo2D(const Line &ref) const
Definition Line.cpp:554
bool isEqual3D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:149
double heightAt(const Point &ref) const
Definition Line.cpp:224
bool isParallelTo3D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:488
vertex_index intersectionWith3D(const Line &ref, XList &inter, double prec=math::eps) const
Definition Line.cpp:373
void flip()
Definition Line.cpp:601
Line & operator*=(double scale)
Definition Line.cpp:93
Point closestPointAlong2D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:282
XPoint::Option intersectionWith2D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:333
Line & operator-=(const Point &offset)
Definition Line.cpp:67
Position positionOf3D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:436
std::shared_ptr< Line > Shared
Shared pointer.
Definition Line.h:29
Line(const Point &origin, double rad, double azim)
Definition Line.h:47
Line operator+(const Point &offset) const
Definition Line.cpp:29
std::unique_ptr< Line > Unique
Unique pointer.
Definition Line.h:27
std::optional< Line > Option
Optional.
Definition Line.h:31
Line operator*(double scale) const
Definition Line.cpp:81
double angleTo(const Line &ref) const
Definition Line.cpp:202
double altitudeAngle() const
Definition Line.cpp:190
double azimuthAngle() const
Definition Line.cpp:180
bool isEqual2D(const Line &ref, double prec=math::eps) const
Definition Line.cpp:135
Line & operator+=(const Point &offset)
Definition Line.cpp:41
void movePolar(double len, double azim, double alt)
Definition Line.cpp:592
Point closestPointAlong3D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:309
bool operator==(const Line &ref) const
Definition Line.h:63
bool encloses3D(const Point &ref, double prec) const
Definition Line.cpp:513
Line(const Point &origin, const Point &end)
Definition Line.h:40
void extend(double len)
Definition Line.cpp:568
Line operator-(const Point &offset) const
Definition Line.cpp:55
Point origin
The line origin.
Definition Line.h:52
double length3D() const
Definition Line.cpp:170
Point closestPointTo3D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:263
Point closestPointTo2D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:242
Position positionOf2D(const Point &ref, double prec=math::eps) const
Definition Line.cpp:405
A 3x3 matrix class.
Definition Matrix3x3.h:16
Definition Point.h:36
Point & movePolar(double len, double angle)
Definition Point.cpp:368
Definition XList.h:24
std::optional< XPoint > Option
Optional.
Definition XPoint.h:41
Definition Anchor2D.h:11
int32_t vertex_index
Index of a vertex, e.g. within a polygon.
Definition Point.h:22
Position
Relative spatial position.
Definition Position.h:12
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22