QCAD
Open Source 2D CAD
RArc.h
Go to the documentation of this file.
1 
20 #ifndef RARC_H
21 #define RARC_H
22 
23 #include "../core_global.h"
24 
25 #include "RShape.h"
26 #include "RVector.h"
27 
28 class RBox;
29 class RPolyline;
30 
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 
48  virtual RShape::Type getShapeType() const {
49  return Arc;
50  }
51 
52  virtual RArc* clone() const {
53  return new RArc(*this);
54  }
55 
56  virtual bool isDirected() const {
57  return true;
58  }
59 
60  virtual void setZ(double z);
61 
62  virtual QList<RVector> getVectorProperties() const;
63  virtual QList<double> getDoubleProperties() const;
64  virtual QList<bool> getBoolProperties() const;
65 
66  bool isValid() const;
67  bool isFullCircle(double tolerance = RS::AngleTolerance) const;
68 
69  static RArc createFrom3Points(const RVector& startPoint,
70  const RVector& point,
71  const RVector& endPoint);
72  static RArc createFrom2PBulge(const RVector& startPoint,
73  const RVector& endPoint,
74  double bulge);
75  static RArc createTangential(const RVector& startPoint,
76  const RVector& pos,
77  double direction,
78  double radius);
79  static QList<RArc> createBiarc(const RVector& startPoint, double startDirection,
80  const RVector& endPoint, double endDirection, bool secondTry = false);
81 
82  virtual RBox getBoundingBox() const;
83 
84  virtual QList<RVector> getEndPoints() const;
85  virtual QList<RVector> getMiddlePoints() const;
86  virtual QList<RVector> getCenterPoints() const;
87  virtual QList<RVector> getArcReferencePoints() const;
88  virtual QList<RVector> getPointsWithDistanceToEnd(
89  double distance, int from = RS::FromAny) const;
90  virtual QList<RVector> getPointCloud(double segmentLength) const;
91 
92  virtual RVector getVectorTo(const RVector& point,
93  bool limited = true, double strictRange = RMAXDOUBLE) const;
94 
95  RVector getCenter() const;
96  void setCenter(const RVector& vector);
97  double getRadius() const;
98  void setRadius(double radius);
99  double getStartAngle() const;
100  void setStartAngle(double startAngle);
101  double getEndAngle() const;
102  void setEndAngle(double endAngle);
103  bool isReversed() const;
104  void setReversed(bool reversed);
105  double getAngleLength(bool allowForZeroLength = false) const;
106  bool isAngleWithinArc(double a) const {
107  return RMath::isAngleBetween(a, startAngle, endAngle, reversed);
108  }
109 
110  double getDiameter() const;
111  void setDiameter(double d);
112  void setLength(double l);
113  double getArea() const;
114  void setArea(double a);
115  double getChordArea() const;
116 
117  virtual double getDirection1() const;
118  virtual double getDirection2() const;
119 
120  virtual RS::Side getSideOfPoint(const RVector& point) const;
121 
122  double getSweep() const;
123  void setSweep(double s);
124  double getLength() const;
125 
126  virtual RVector getStartPoint() const;
127  virtual RVector getEndPoint() const;
128  RVector getPointAtAngle(double a) const;
129  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
130  virtual RVector getMiddlePoint() const;
131 
132  void moveStartPoint(const RVector& pos);
133  void moveEndPoint(const RVector& pos);
134  void moveMiddlePoint(const RVector& pos);
135  double getBulge() const;
136 
137  virtual bool move(const RVector& offset);
138  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
139  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
140  virtual bool mirror(const RLine& axis);
141  virtual bool reverse();
142  virtual bool stretch(const RPolyline& area, const RVector& offset);
143 
144  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
145 
146  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
147  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
148  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
149  virtual bool trimStartPoint(double trimDist) {
150  return RShape::trimStartPoint(trimDist);
151  }
152  virtual bool trimEndPoint(double trimDist) {
153  return RShape::trimEndPoint(trimDist);
154  }
155  virtual double getDistanceFromStart(const RVector& p) const;
156 
157  RPolyline approximateWithLines(double segmentLength, double angle = 0.0) const;
158  RPolyline approximateWithLinesTan(double segmentLength, double angle = 0.0) const;
159 
160  QList<RLine> getTangents(const RVector& point) const;
161 
162  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid) {
163  return RShape::getOffsetArcs(*this, distance, number, side, position);
164  }
165 
166  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
167 
168  QList<RArc> splitAtQuadrantLines() const;
169 
170 protected:
171  virtual void print(QDebug dbg) const;
172 
173 public:
183  double radius;
188  double startAngle;
193  double endAngle;
198  bool reversed;
199 };
200 
201 Q_DECLARE_METATYPE(const RArc*)
204 Q_DECLARE_METATYPE(QSharedPointer<RArc>)
205 Q_DECLARE_METATYPE(QSharedPointer<RArc>*)
206 
207 #endif
RShape::splitAt
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2114
RShape::getOffsetArcs
static QList< QSharedPointer< RShape > > getOffsetArcs(const RShape &shape, double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RShape.cpp:1994
RArc::radius
double radius
Getter function for this property: getRadius Setter function for this property: setRadius
Definition: RArc.h:183
RShape::getTransformed
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
RShape::trimEndPoint
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:322
RArc::isAngleWithinArc
bool isAngleWithinArc(double a) const
Definition: RArc.h:106
RShape::getLength
virtual double getLength() const =0
RShape::move
virtual bool move(const RVector &offset)=0
RShape::stretch
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1740
RS::AngleTolerance
static const double AngleTolerance
Definition: RS.h:697
RShape::getMiddlePoints
virtual QList< RVector > getMiddlePoints() const =0
RS::Side
Side
Side used for side of a point relativ to an entity (right hand or left hand side)
Definition: RS.h:204
RArc::trimEndPoint
virtual bool trimEndPoint(double trimDist)
Definition: RArc.h:152
RArc::startAngle
double startAngle
Getter function for this property: getStartAngle Setter function for this property: setStartAngle
Definition: RArc.h:188
RArc::isDirected
virtual bool isDirected() const
Definition: RArc.h:56
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RS::Ending
Ending
Entity ending.
Definition: RS.h:214
RS::FromStart
@ FromStart
Definition: RS.h:263
RShape::getVectorProperties
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:165
RShape::getCenterPoints
virtual QList< RVector > getCenterPoints() const =0
RArc::clone
virtual RArc * clone() const
Definition: RArc.h:52
RArc::reversed
bool reversed
Getter function for this property: isReversed Setter function for this property: setReversed
Definition: RArc.h:198
RArc
Low-level mathematical representation of an arc.
Definition: RArc.h:40
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RShape::getTrimEnd
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition: RShape.h:339
RShape::Type
Type
Definition: RShape.h:74
RShape::Arc
@ Arc
Definition: RShape.h:78
RShape::scale
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1755
RShape
Interface for geometrical shape classes.
Definition: RShape.h:72
RShape::trimStartPoint
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:303
RShape.h
RDEFAULT_RVECTOR
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
RShape::getVectorTo
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
RVector.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
RShape::getDirection1
virtual double getDirection1() const
Definition: RShape.h:271
RArc::trimStartPoint
virtual bool trimStartPoint(double trimDist)
Definition: RArc.h:149
RShape::getDistanceFromStart
virtual double getDistanceFromStart(const RVector &p) const
Definition: RShape.h:350
RArc::getShapeType
virtual RShape::Type getShapeType() const
Definition: RArc.h:48
RShape::getDoubleProperties
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:167
RShape::getBoolProperties
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:168
RArc::center
RVector center
Getter function for this property: getCenter Setter function for this property: setCenter
Definition: RArc.h:178
RShape::getPointCloud
virtual QList< RVector > getPointCloud(double segmentLength) const =0
RShape::getBoundingBox
virtual RBox getBoundingBox() const =0
RShape::getSideOfPoint
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition: RShape.h:278
RShape::getEndPoints
virtual QList< RVector > getEndPoints() const =0
RMAXDOUBLE
#define RMAXDOUBLE
Definition: RMath.h:63
RShape::getArcReferencePoints
virtual QList< RVector > getArcReferencePoints() const
Definition: RShape.h:211
RArc::getOffsetShapes
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RArc.h:162
RShape::getStartPoint
virtual RVector getStartPoint() const
Definition: RShape.h:283
RShape::mirror
virtual bool mirror(const RLine &axis)=0
RShape::getPointsWithDistanceToEnd
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
RShape::setZ
virtual void setZ(double z)=0
RS::FromAny
@ FromAny
Start or end.
Definition: RS.h:265
RShape::getDirection2
virtual double getDirection2() const
Definition: RShape.h:274
RShape::print
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1759
RShape::getMiddlePoint
virtual RVector getMiddlePoint() const
Definition: RShape.h:289
RMath::isAngleBetween
static bool isAngleBetween(double a, double a1, double a2, bool reversed)
Tests if angle a is between a1 and a2.
Definition: RMath.cpp:599
RShape::reverse
virtual bool reverse()
Definition: RShape.h:293
RBox
Represents a box e.g.
Definition: RBox.h:43
RArc::endAngle
double endAngle
Getter function for this property: getEndAngle Setter function for this property: setEndAngle
Definition: RArc.h:193
RVector::invalid
static const RVector invalid
invalid vector
Definition: RVector.h:322
RS::From
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:262
RShape::getAngleAt
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:244
RShape::getEndPoint
virtual RVector getEndPoint() const
Definition: RShape.h:286
RPolyline
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RShape::rotate
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0