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 "RDirected.h"
26 #include "RShape.h"
27 #include "RVector.h"
29 class RBox;
30 class RPolyline;
41 class QCADCORE_EXPORT RArc: public RShape, public RDirected {
42 public:
43  RArc();
44  RArc(double cx, double cy, double radius, double startAngle,
45  double endAngle, bool reversed = false);
46  RArc(const RVector& center, double radius, double startAngle,
47  double endAngle, bool reversed = false);
48  virtual ~RArc();
50  virtual RShape::Type getType() const {
51  return Arc;
52  }
54  virtual RArc* clone() const {
55  return new RArc(*this);
56  }
58  virtual void to2D();
60  bool isValid() const;
61  bool isFullCircle(double tolerance = RS::AngleTolerance) const;
63  static RArc createFrom3Points(const RVector& startPoint,
64  const RVector& point,
65  const RVector& endPoint);
66  static RArc createFrom2PBulge(const RVector& startPoint,
67  const RVector& endPoint,
68  double bulge);
69  static RArc createTangential(const RVector& startPoint,
70  const RVector& pos,
71  double direction,
72  double radius);
73  static QList<RArc> createBiarc(const RVector& startPoint, double startDirection,
74  const RVector& endPoint, double endDirection, bool secondTry = false);
76  virtual RBox getBoundingBox() const;
78  virtual QList<RVector> getEndPoints() const;
79  virtual QList<RVector> getMiddlePoints() const;
80  virtual QList<RVector> getCenterPoints() const;
81  virtual QList<RVector> getPointsWithDistanceToEnd(
82  double distance, RS::From from = RS::FromAny) const;
84  virtual RVector getVectorTo(const RVector& point,
85  bool limited = true, double strictRange = RMAXDOUBLE) const;
87  RVector getCenter() const;
88  void setCenter(const RVector& vector);
89  double getRadius() const;
90  void setRadius(double radius);
91  double getStartAngle() const;
92  void setStartAngle(double startAngle);
93  double getEndAngle() const;
94  void setEndAngle(double endAngle);
95  bool isReversed() const;
96  void setReversed(bool reversed);
97  double getAngleLength(bool allowForZeroLength = false) const;
98  bool isAngleWithinArc(double a) {
99  return RMath::isAngleBetween(a, startAngle, endAngle, reversed);
100  }
102  double getDiameter() const;
103  void setDiameter(double d);
104  void setLength(double l);
105  double getArea() const;
106  void setArea(double a);
107  double getChordArea() const;
109  virtual double getDirection1() const;
110  virtual double getDirection2() const;
112  virtual RS::Side getSideOfPoint(const RVector& point) const;
114  double getSweep() const;
115  void setSweep(double s);
116  double getLength() const;
118  virtual RVector getStartPoint() const;
119  virtual RVector getEndPoint() const;
120  RVector getPointAtAngle(double a) const;
121  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
122  virtual RVector getMiddlePoint() const;
124  void moveStartPoint(const RVector& pos);
125  void moveEndPoint(const RVector& pos);
126  void moveMiddlePoint(const RVector& pos);
127  double getBulge() const;
129  virtual bool move(const RVector& offset);
130  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
131  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
132  virtual bool mirror(const RLine& axis);
133  virtual bool reverse();
134  virtual bool stretch(const RPolyline& area, const RVector& offset);
136  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
138  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
139  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
140  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
141  virtual double getDistanceFromStart(const RVector& p) const;
143  RPolyline approximateWithLines(double segmentLength);
144  RPolyline approximateWithLinesTan(double segmentLength);
146  QList<RLine> getTangents(const RVector& point) const;
148  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid) {
149  return RShape::getOffsetArcs(*this, distance, number, side, position);
150  }
152  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
154 protected:
155  virtual void print(QDebug dbg) const;
157 public:
167  double radius;
172  double startAngle;
177  double endAngle;
182  bool reversed;
183 };
188 Q_DECLARE_METATYPE(QSharedPointer<RArc>)
189 Q_DECLARE_METATYPE(QSharedPointer<RArc>*)
191 #endif
static const double AngleTolerance
Definition: RS.h:552
Represents a box e.g.
Definition: RBox.h:43
Entity ending.
Definition: RS.h:150
RVector center
Getter function for this property: getCenter.
Definition: RArc.h:162
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 QList< RVector > getEndPoints() const =0
double radius
Getter function for this property: getRadius.
Definition: RArc.h:167
Low-level mathematical representation of an arc.
Definition: RArc.h:41
bool reversed
Getter function for this property: isReversed.
Definition: RArc.h:182
virtual double getDirection1() const =0
void mirror(void e, void p1, void p2, void p3, void p4)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:41
virtual RVector getEndPoint() const =0
Definition: core_global.h:10
void rotate(void e, void angle, void p1, void p2)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:54
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RArc.h:148
void move(void e, void p1, void p2)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:14
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
bool isAngleWithinArc(double a)
Definition: RArc.h:98
Start or end.
Definition: RS.h:201
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)=0
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:140
virtual double getDistanceFromStart(const RVector &p) const
Definition: RDirected.h:77
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:170
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2032
virtual bool stretch(const RBox &area, const RVector &offset)
Definition: RShape.cpp:1665
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 QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny) const =0
virtual QList< RVector > getMiddlePoints() const =0
virtual RShape::Type getType() const
Definition: RArc.h:50
Definition: RShape.h:54
Definition: RMath.h:63
void scale(void e, void factor, void p1, void p2)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:27
Definition: RS.h:199
Low-level mathematical representation of a line.
Definition: RLine.h:42
double startAngle
Getter function for this property: getStartAngle.
Definition: RArc.h:172
virtual RS::Side getSideOfPoint(const RVector &point) const =0
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)=0
virtual RVector getStartPoint() const =0
virtual RArc * clone() const
Definition: RArc.h:54
virtual bool reverse()=0
static QList< QSharedPointer< RShape > > getOffsetArcs(const RShape &shape, double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RShape.cpp:1909
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDirected.h:36
double endAngle
Getter function for this property: getEndAngle.
Definition: RArc.h:177
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:198
virtual double getDirection2() const =0
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
virtual RVector getMiddlePoint() const =0
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1680
static const RVector invalid
invalid vector
Definition: RVector.h:307
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)=0
Definition: RVector.h:37