ActiveLib
Loading...
Searching...
No Matches
Arc.h
1
6#ifndef ACTIVE_GEOMETRY_ARC
7#define ACTIVE_GEOMETRY_ARC
8
9#include "Active/Geometry/Box.h"
10#include "Active/Geometry/Plane.h"
11#include "Active/Geometry/Point.h"
12#include "Active/Geometry/PolyPoint.h"
13#include "Active/Geometry/Vector3.h"
14
15#include <memory>
16
17namespace active::geometry {
18
19 class Leveller;
20 class Line;
21 class Matrix3x3;
22 class XList;
23
25 class Arc : public utility::Cloner {
26 public:
27
28 // MARK: - Types
29
30 using enum Position;
31
33 using Unique = std::unique_ptr<Arc>;
35 using Shared = std::shared_ptr<Arc>;
37 using Option = std::optional<Arc>;
38
39 // MARK: - Constructors
40
44 Arc();
52 Arc(const Point& centre, double radius, double sweep = 2.0 * math::pi, double start = 0, const Vector3& norm = Vector3(0, 0, 1));
60 Arc(const Point& centre, const Point& pt1, const Point& pt2, bool isClockwise);
67 Arc(const Point& pt1, const Point& pt2, const Point& pt3);
73 Arc(const Point& origin, const PolyPoint& end);
74
79 Arc* clonePtr() const { return new Arc(*this); }
80
81 // MARK: - Variables
82
83 //The arc centre
84 Point centre;
85 //The normal of the plane the arc lies along
86 Vector3 normal;
87 //The arc radius
88 double radius;
89 //The arc start angle
90 double startAngle;
91 //The arc sweep angle
92 double sweep;
93
94 // MARK: - Operators
95
101 bool operator== (const Arc& ref) const { return isEqual3D(ref); }
107 bool operator!= (const Arc& ref) const { return !isEqual3D(ref); }
113 Arc& operator= (const Arc& source);
119 Arc operator+ (const Point& offset) const;
125 Arc& operator+= (const Point& offset);
131 Arc operator- (const Point& offset) const;
137 Arc& operator-= (const Point& offset);
143 Arc operator* (double scale) const;
149 Arc& operator*= (double scale);
155 Arc operator* (const Matrix3x3& matrix) const;
161 Arc& operator*= (const Matrix3x3& matrix);
162
163 // MARK: - Functions (const)
164
169 double isValid(double prec = math::eps) const;
176 bool isEqual2D(const Arc& ref, double prec = math::eps) const;
183 bool isEqual3D(const Arc& ref, double prec = math::eps) const;
188 Point getOrigin() const;
193 PolyPoint getEnd() const;
198 Point midpoint() const;
203 double getEndAngle() const { return startAngle + sweep; }
208 Plane getPlane() const;
213 Box::Unique bounds() const;
218 double length2D() const;
223 double length3D() const;
230 double getArea(bool isArcOnly = true, bool isResultSigned = false) const;
236 bool isColinearTo2D(const Arc& ref, double prec = math::eps) const;
242 bool isColinearTo3D(const Arc& ref, double prec = math::eps) const;
248 bool isParallelTo2D(const Arc& ref, double prec = math::eps) const;
254 bool isParallelTo3D(const Arc& ref, double prec = math::eps) const;
260 Point closestPointAlong2D(const Point& ref, double prec = math::eps) const;
266 Point closestPointAlong3D(const Point& ref, double prec = math::eps) const;
272 Point closestPointTo2D(const Point& ref, double prec = math::eps) const;
278 Point closestPointTo3D(const Point& ref, double prec = math::eps) const;
286 vertex_index intersectionWith(const Plane& ref, XList& inter, double prec = math::eps) const;
294 vertex_index intersectionWith2D(const Line& ref, XList& inter, double prec = math::eps) const;
302 vertex_index intersectionWith2D(const Arc& ref, XList& inter, double prec = math::eps) const;
310 vertex_index intersectionWith3D(const Line& ref, XList& inter, double prec = math::eps) const;
318 vertex_index intersectionWith3D(const Arc& ref, XList& inter, double prec = math::eps) const;
325 Position positionOf2D(const Point& ref, double prec = math::eps) const;
332 Position positionOf3D(const Point& ref, double prec = math::eps) const;
338 bool encloses2D(const Point& ref, double prec = math::eps) const;
344 bool encloses3D(const Point& ref, double prec = math::eps) const;
345
346 // MARK: - Functions (mutating)
347
352 void setEndAngle(double end) { sweep = end - startAngle; }
359 void movePolar(double len, double azim, double alt);
365 void movePolar(double len, double angle);
370 void expand(double inc) { radius += inc; }
375 void spin(double rotAngle) { startAngle += rotAngle; }
379 void flip();
380
381 protected:
387 void initLevel(Leveller& level, double prec = math::eps) const;
397 bool createIntersect(const Point& pt, const Arc& arc, const Arc& ref,
398 XList& inter, double prec = math::eps) const;
408 bool createIntersect(const Point& pt, const Arc& arc, const Line& ref,
409 XList& inter, double prec = math::eps) const;
417 vertex_index intersectionWithLevel(const Line& ref, XList& inter, double prec = math::eps) const;
425 vertex_index intersectionWithLevel(const Arc& ref, XList& inter, double prec = math::eps) const;
426 };
427
428}
429
430#endif //ACTIVE_GEOMETRY_ARC
Class to represent an arc.
Definition Arc.h:25
bool isParallelTo3D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:482
void flip()
Definition Arc.cpp:809
bool createIntersect(const Point &pt, const Arc &arc, const Arc &ref, XList &inter, double prec=math::eps) const
Definition Arc.cpp:836
void movePolar(double len, double azim, double alt)
Definition Arc.cpp:801
Arc & operator=(const Arc &source)
Definition Arc.cpp:140
std::optional< Arc > Option
Optional.
Definition Arc.h:37
Point closestPointTo3D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:544
double length3D() const
Definition Arc.cpp:431
PolyPoint getEnd() const
Definition Arc.cpp:331
double getEndAngle() const
Definition Arc.h:203
bool operator==(const Arc &ref) const
Definition Arc.h:101
Point closestPointAlong2D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:494
bool encloses3D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:772
Arc & operator-=(const Point &offset)
Definition Arc.cpp:196
Arc operator+(const Point &offset) const
Definition Arc.cpp:159
void expand(double inc)
Definition Arc.h:370
Arc operator*(double scale) const
Definition Arc.cpp:209
Arc operator-(const Point &offset) const
Definition Arc.cpp:184
Box::Unique bounds() const
Definition Arc.cpp:373
vertex_index intersectionWith3D(const Line &ref, XList &inter, double prec=math::eps) const
Definition Arc.cpp:631
vertex_index intersectionWithLevel(const Line &ref, XList &inter, double prec=math::eps) const
Definition Arc.cpp:874
Arc * clonePtr() const
Definition Arc.h:79
void setEndAngle(double end)
Definition Arc.h:352
Position positionOf2D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:708
bool encloses2D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:759
bool isEqual2D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:277
Arc & operator*=(double scale)
Definition Arc.cpp:221
bool isEqual3D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:299
Arc()
Definition Arc.cpp:29
Point getOrigin() const
Definition Arc.cpp:318
bool isColinearTo2D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:443
vertex_index intersectionWith(const Plane &ref, XList &inter, double prec=math::eps) const
Definition Arc.cpp:566
Position positionOf3D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:740
Point closestPointAlong3D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:519
std::shared_ptr< Arc > Shared
Shared pointer.
Definition Arc.h:35
bool isColinearTo3D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:457
void initLevel(Leveller &level, double prec=math::eps) const
Definition Arc.cpp:822
bool operator!=(const Arc &ref) const
Definition Arc.h:107
Point closestPointTo2D(const Point &ref, double prec=math::eps) const
Definition Arc.cpp:532
bool isParallelTo2D(const Arc &ref, double prec=math::eps) const
Definition Arc.cpp:470
Arc & operator+=(const Point &offset)
Definition Arc.cpp:171
double getArea(bool isArcOnly=true, bool isResultSigned=false) const
Definition Arc.cpp:403
std::unique_ptr< Arc > Unique
Unique pointer.
Definition Arc.h:33
vertex_index intersectionWith2D(const Line &ref, XList &inter, double prec=math::eps) const
Definition Arc.cpp:587
Point midpoint() const
Definition Arc.cpp:346
double length2D() const
Definition Arc.cpp:421
double isValid(double prec=math::eps) const
Definition Arc.cpp:263
void spin(double rotAngle)
Definition Arc.h:375
Plane getPlane() const
Definition Arc.cpp:362
std::unique_ptr< Box > Unique
Unique pointer.
Definition Box.h:27
Class to reorientate geometric objects to a horizontal plane.
Definition Leveller.h:20
Class to represent a line.
Definition Line.h:21
A 3x3 matrix class.
Definition Matrix3x3.h:16
Class to represent a plane.
Definition Plane.h:21
Definition Point.h:36
Definition PolyPoint.h:24
A 1x3 vector class.
Definition Vector3.h:20
Definition XList.h:24
Definition Cloner.h:17
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
@ origin
On the origin of an edge.
@ end
On the end of an edge.
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22