LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
geoarc.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "cad/const.h"
4 #include "geoarea.h"
5 #include "geocoordinate.h"
6 #include "geobase.h"
7 #include <vector>
8 #include "cad/math/equation.h"
9 
10 namespace lc {
11  namespace geo {
12 
13  class Arc : public Base, virtual public Visitable {
14  public:
15 
26  Arc(const Coordinate& center, double radius, double startAngle, double endAngle);
35  Arc(const Coordinate& center, double radius, double startAngle, double endAngle, bool CCW);
36 
37  static Arc createArc3P(const Coordinate& p1, const Coordinate& p2, const Coordinate& p3);
38  static Arc createArcBulge(const Coordinate& p1, const Coordinate& p2, const double bulge);
39 
41  Arc(Arc &&c) noexcept {
42  std::swap(_center, c._center);
43  std::swap(_radius, c._radius);
44  std::swap(_startAngle, c._startAngle);
45  std::swap(_endAngle, c._endAngle);
46  std::swap(_CCW, c._CCW);
47  }
48 
49  Arc& operator = (Arc&& c) noexcept {
50  std::swap(_center, c._center);
51  std::swap(_radius, c._radius);
52  std::swap(_startAngle, c._startAngle);
53  std::swap(_endAngle, c._endAngle);
54  std::swap(_CCW, c._CCW);
55  return *this;
56  }
57 
58 
63  const Coordinate center() const;
64 
69  double radius() const;
74  double startAngle() const;
79  double endAngle() const;
80 
86  double length() const;
87 
91  Coordinate startP() const;
92 
96  Coordinate endP() const;
97 
101  Area boundingBox() const;
102 
107  bool CCW() const;
108 
109  Coordinate nearestPointOnPath(const Coordinate& coord) const;
110  Coordinate nearestPointOnEntity(const Coordinate& coord) const;
111 
112  const maths::Equation equation() const {
113  return maths::Equation(1., 0.,1., 0., 0., -_radius* _radius).move(_center);
114  }
115 
116 
117  // test of the given angle is between the start and end angle of this arc.
118  bool isAngleBetween(double angle) const;
119 
120  virtual void accept(GeoEntityVisitor &v) const override { v.visit(*this); }
121 
126  double angle() const;
127 
132  double bulge() const;
133  private:
134  friend std::ostream& operator<<(std::ostream& os, const Arc& a) {
135  os << "Arc(center=" << a._center << " radius=" << a._radius << " startAngle=" << a._startAngle << " endAngle=" << a._endAngle << " ccw=" << a._CCW << ")";
136  return os;
137  }
138 
139  private:
141  double _radius;
142  double _startAngle;
143  double _endAngle;
144  bool _CCW;
145  };
146  }
147 }
Arc(Arc &&c) noexcept
Definition: geoarc.h:41
double _startAngle
Double startAngle of Arc.
Definition: geoarc.h:142
double angle() const
Definition: geoarc.cpp:167
Coordinate nearestPointOnEntity(const Coordinate &coord) const
Definition: geoarc.cpp:98
Coordinate startP() const
Definition: geoarc.cpp:130
Area boundingBox() const
Definition: geoarc.cpp:138
Arc & operator=(Arc &&c) noexcept
Definition: geoarc.h:49
static Arc createArc3P(const Coordinate &p1, const Coordinate &p2, const Coordinate &p3)
Definition: geoarc.cpp:27
friend std::ostream & operator<<(std::ostream &os, const Arc &a)
Definition: geoarc.h:134
Arc(const Arc &c)
Definition: geoarc.h:40
double length() const
Definition: geoarc.cpp:118
double _endAngle
Double endAngle of Arc.
Definition: geoarc.h:143
static Arc createArcBulge(const Coordinate &p1, const Coordinate &p2, const double bulge)
Definition: geoarc.cpp:51
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
Definition: cadentity.h:12
Coordinate _center
Coordinate center of Arc.
Definition: geoarc.h:140
Coordinate nearestPointOnPath(const Coordinate &coord) const
Definition: geoarc.cpp:95
bool _CCW
Definition: geoarc.h:144
Arc(const Coordinate &center, double radius, double startAngle, double endAngle)
Definition: geoarc.cpp:8
const maths::Equation equation() const
Definition: geoarc.h:112
Coordinate endP() const
Definition: geoarc.cpp:134
double _radius
Double _Radius of Arc.
Definition: geoarc.h:141
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
virtual void accept(GeoEntityVisitor &v) const override
Definition: geoarc.h:120
const Equation move(const geo::Coordinate &v) const
move the quadratic equation by value V
Definition: equation.cpp:48
double bulge() const
Definition: geoarc.cpp:171
bool isAngleBetween(double angle) const
Definition: geoarc.cpp:163
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91