Open Source 2D CAD
Go to the documentation of this file.
20 #ifndef RARC_H
21 #define RARC_H
23 #include "../core_global.h"
25 #include "RShape.h"
26 #include "RVector.h"
28 class RBox;
29 class RPolyline;
40 class QCADCORE_EXPORT RArc: public RShape {
41 public:
42  RArc();
43  RArc(double cx, double cy, double radius, double startAngle,
44  double endAngle, bool reversed = false);
45  RArc(const RVector& center, double radius, double startAngle,
46  double endAngle, bool reversed = false);
47  virtual ~RArc();
49  virtual RShape::Type getType() const {
50  return Arc;
51  }
53  virtual RArc* clone() const {
54  return new RArc(*this);
55  }
57  virtual bool isDirected() const {
58  return true;
59  }
61  virtual void to2D();
63  virtual QList<RVector> getVectorProperties() const;
64  virtual QList<double> getDoubleProperties() const;
65  virtual QList<bool> getBoolProperties() const;
67  bool isValid() const;
68  bool isFullCircle(double tolerance = RS::AngleTolerance) const;
70  static RArc createFrom3Points(const RVector& startPoint,
71  const RVector& point,
72  const RVector& endPoint);
73  static RArc createFrom2PBulge(const RVector& startPoint,
74  const RVector& endPoint,
75  double bulge);
76  static RArc createTangential(const RVector& startPoint,
77  const RVector& pos,
78  double direction,
79  double radius);
80  static QList<RArc> createBiarc(const RVector& startPoint, double startDirection,
81  const RVector& endPoint, double endDirection, bool secondTry = false);
83  virtual RBox getBoundingBox() const;
85  virtual QList<RVector> getEndPoints() const;
86  virtual QList<RVector> getMiddlePoints() const;
87  virtual QList<RVector> getCenterPoints() const;
88  virtual QList<RVector> getPointsWithDistanceToEnd(
89  double distance, int from = RS::FromAny) const;
91  virtual RVector getVectorTo(const RVector& point,
92  bool limited = true, double strictRange = RMAXDOUBLE) const;
94  RVector getCenter() const;
95  void setCenter(const RVector& vector);
96  double getRadius() const;
97  void setRadius(double radius);
98  double getStartAngle() const;
99  void setStartAngle(double startAngle);
100  double getEndAngle() const;
101  void setEndAngle(double endAngle);
102  bool isReversed() const;
103  void setReversed(bool reversed);
104  double getAngleLength(bool allowForZeroLength = false) const;
105  bool isAngleWithinArc(double a) {
106  return RMath::isAngleBetween(a, startAngle, endAngle, reversed);
107  }
109  double getDiameter() const;
110  void setDiameter(double d);
111  void setLength(double l);
112  double getArea() const;
113  void setArea(double a);
114  double getChordArea() const;
116  virtual double getDirection1() const;
117  virtual double getDirection2() const;
119  virtual RS::Side getSideOfPoint(const RVector& point) const;
121  double getSweep() const;
122  void setSweep(double s);
123  double getLength() const;
125  virtual RVector getStartPoint() const;
126  virtual RVector getEndPoint() const;
127  RVector getPointAtAngle(double a) const;
128  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
129  virtual RVector getMiddlePoint() const;
131  void moveStartPoint(const RVector& pos);
132  void moveEndPoint(const RVector& pos);
133  void moveMiddlePoint(const RVector& pos);
134  double getBulge() const;
136  virtual bool move(const RVector& offset);
137  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
138  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
139  virtual bool mirror(const RLine& axis);
140  virtual bool reverse();
141  virtual bool stretch(const RPolyline& area, const RVector& offset);
143  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
145  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
146  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
147  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
148  virtual bool trimStartPoint(double trimDist) {
149  return RShape::trimStartPoint(trimDist);
150  }
151  virtual bool trimEndPoint(double trimDist) {
152  return RShape::trimEndPoint(trimDist);
153  }
154  virtual double getDistanceFromStart(const RVector& p) const;
156  RPolyline approximateWithLines(double segmentLength);
157  RPolyline approximateWithLinesTan(double segmentLength);
159  QList<RLine> getTangents(const RVector& point) const;
161  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid) {
162  return RShape::getOffsetArcs(*this, distance, number, side, position);
163  }
165  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
167 protected:
168  virtual void print(QDebug dbg) const;
170 public:
180  double radius;
185  double startAngle;
190  double endAngle;
195  bool reversed;
196 };
201 Q_DECLARE_METATYPE(QSharedPointer<RArc>)
202 Q_DECLARE_METATYPE(QSharedPointer<RArc>*)
204 #endif
static const double AngleTolerance
Definition: RS.h:554
Represents a box e.g.
Definition: RBox.h:43
Entity ending.
Definition: RS.h:152
RVector center
Getter function for this property: getCenter.
Definition: RArc.h:175
Definition: RShape.h:58
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
virtual void to2D()=0
Flattens this shape to the X/Y plane.
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:262
virtual QList< RVector > getEndPoints() const =0
double radius
Getter function for this property: getRadius.
Definition: RArc.h:180
virtual RVector getEndPoint() const
Definition: RShape.h:245
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:141
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:143
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:144
Low-level mathematical representation of an arc.
Definition: RArc.h:40
bool reversed
Getter function for this property: isReversed.
Definition: RArc.h:195
virtual bool reverse()
Definition: RShape.h:252
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
Definition: core_global.h:10
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RArc.h:161
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
bool isAngleWithinArc(double a)
Definition: RArc.h:105
Start or end.
Definition: RS.h:203
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:281
virtual double getDirection1() const
Definition: RShape.h:230
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:142
virtual bool trimStartPoint(double trimDist)
Definition: RArc.h:148
virtual bool move(const RVector &offset)=0
virtual double getDirection2() const
Definition: RShape.h:233
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:208
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2065
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1699
static bool isAngleBetween(double a, double a1, double a2, bool reversed)
Tests if angle a is between a1 and a2.
Definition: RMath.cpp:570
virtual RVector getMiddlePoint() const
Definition: RShape.h:248
virtual QList< RVector > getMiddlePoints() const =0
virtual RShape::Type getType() const
Definition: RArc.h:49
Definition: RShape.h:54
Definition: RMath.h:63
Definition: RS.h:201
virtual bool mirror(const RLine &axis)=0
Low-level mathematical representation of a line.
Definition: RLine.h:41
double startAngle
Getter function for this property: getStartAngle.
Definition: RArc.h:185
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition: RShape.h:237
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition: RShape.h:298
virtual RArc * clone() const
Definition: RArc.h:53
static QList< QSharedPointer< RShape > > getOffsetArcs(const RShape &shape, double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RShape.cpp:1945
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
double endAngle
Getter function for this property: getEndAngle.
Definition: RArc.h:190
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:200
virtual bool trimEndPoint(double trimDist)
Definition: RArc.h:151
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1710
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1714
static const RVector invalid
invalid vector
Definition: RVector.h:313
virtual bool isDirected() const
Definition: RArc.h:57
virtual RVector getStartPoint() const
Definition: RShape.h:242
Definition: RVector.h:37
virtual double getDistanceFromStart(const RVector &p) const
Definition: RShape.h:309