QCAD
Open Source 2D CAD
REllipse.h
Go to the documentation of this file.
1 
20 #ifndef RELLIPSE_H
21 #define RELLIPSE_H
22 
23 #include "../core_global.h"
24 
25 #include "RShape.h"
26 #include "RSpline.h"
27 #include "REllipseProxy.h"
28 #include "RLine.h"
29 #include "RVector.h"
30 
31 class RBox;
32 
43 public:
44  REllipse();
45  REllipse(const RVector& center,
46  const RVector& majorPoint,
47  double ratio,
48  double startParam, double endParam,
49  bool reversed);
50  virtual ~REllipse();
51 
52  static REllipse createInscribed(const RVector& p1, const RVector& p2, const RVector& p3, const RVector& p4);
53 
54  virtual RShape::Type getShapeType() const {
55  return Ellipse;
56  }
57 
58  virtual REllipse* clone() const {
59  return new REllipse(*this);
60  }
61 
62  virtual bool isDirected() const {
63  return true;
64  }
65 
66  bool isValid();
67 
68  virtual void setZ(double z);
69 
70  virtual QList<RVector> getVectorProperties() const;
71  virtual QList<double> getDoubleProperties() const;
72  virtual QList<bool> getBoolProperties() const;
73 
74  virtual RBox getBoundingBox() const;
75 
76  virtual QList<RVector> getEndPoints() const;
77  virtual QList<RVector> getMiddlePoints() const;
78  virtual QList<RVector> getCenterPoints() const;
79  virtual QList<RVector> getPointsWithDistanceToEnd(
80  double distance, int from = RS::FromAny) const;
81  virtual QList<RVector> getPointCloud(double segmentLength) const;
82 
83  virtual RVector getVectorTo(const RVector& point,
84  bool limited = true, double strictRange = RMAXDOUBLE) const;
85 
86  void moveStartPoint(const RVector& pos, bool changeAngleOnly=false);
87  void moveEndPoint(const RVector& pos, bool changeAngleOnly=false);
88 
89  QList<RVector> getFoci() const;
90 
91  RVector getCenter() const;
92  void setCenter(const RVector& vector);
93  RVector getMajorPoint() const;
94  RVector getMinorPoint() const;
95  void setMajorPoint(const RVector& vector);
96  void setMinorPoint(const RVector &p);
97  bool switchMajorMinor();
98  double getRatio() const;
99  void setRatio(double radius);
100 
101  double getStartParam() const;
102  void setStartParam(double startParam);
103 
104  double getEndParam() const;
105  void setEndParam(double endParam);
106 
107  double getStartAngle() const;
108  void setStartAngle(double a);
109 
110  double angleToParam(double a) const;
111 
112  double getEndAngle() const;
113  void setEndAngle(double a);
114 
115  double getAngleLength(bool allowForZeroLength = false) const;
116 
117  bool isAngleWithinArc(double a) const {
118  if (isFullEllipse()) {
119  return true;
120  }
121  return RMath::isAngleBetween(a, getStartAngle(), getEndAngle(), reversed);
122  }
123  bool isParamWithinArc(double a) const {
124  if (isFullEllipse()) {
125  return true;
126  }
127  return RMath::isAngleBetween(a, getStartParam(), getEndParam(), reversed);
128  }
129 
130  bool isReversed() const;
131  void setReversed(bool reversed);
132 
133  virtual double getDirection1() const;
134  virtual double getDirection2() const;
135 
136  virtual RS::Side getSideOfPoint(const RVector& point) const;
137 
138  virtual RVector getStartPoint() const;
139  virtual RVector getEndPoint() const;
140  double getMajorRadius() const;
141  double getMinorRadius() const;
142  double getAngle() const;
143  void setAngle(double a);
144  bool isFullEllipse() const;
145  bool isCircular() const;
146  double getLength() const;
147  double getSimpsonLength(double f1, double f2) const;
148 
149  bool contains(const RVector& p) const;
150 
151  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
152 
153  double getAngleAtPoint(const RVector& pos) const;
154  double getParamTo(const RVector& pos) const;
155  double getRadiusAt(double param) const;
156  RVector getPointAt(double param) const;
157  RVector getMiddlePoint() const;
158 
159  virtual bool move(const RVector& offset);
160  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
161  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
162  virtual bool mirror(const RLine& axis);
163 
164  virtual bool reverse();
165 
166  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
167 
168  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
169  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
170  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
171  virtual bool trimStartPoint(double trimDist) {
172  return RShape::trimStartPoint(trimDist);
173  }
174  virtual bool trimEndPoint(double trimDist) {
175  return RShape::trimEndPoint(trimDist);
176  }
177 
178  void correctMajorMinor();
179  double getSweep() const;
180 
181  QList<RVector> getBoxCorners();
182 
183  QList<RLine> getTangents(const RVector& point) const;
184 
185  QList<RSpline> approximateWithSplines() const;
186  RPolyline approximateWithArcs(int segments) const;
187 
188  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
189  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
190 
191  static bool hasProxy() {
192  return ellipseProxy!=NULL;
193  }
194 
198  static void setEllipseProxy(REllipseProxy* p) {
199  if (ellipseProxy!=NULL) {
200  delete ellipseProxy;
201  }
202  ellipseProxy = p;
203  }
204 
209  return ellipseProxy;
210  }
211 
212 protected:
213  virtual void print(QDebug dbg) const;
214 
215 public:
230  double ratio;
235  double startParam;
240  double endParam;
245  bool reversed;
246 
247 private:
249 };
250 
254 Q_DECLARE_METATYPE(QSharedPointer<REllipse>)
255 Q_DECLARE_METATYPE(QSharedPointer<REllipse>*)
256 
257 #endif
RShape::Ellipse
@ Ellipse
Definition: RShape.h:80
RShape::splitAt
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2114
REllipse::getShapeType
virtual RShape::Type getShapeType() const
Definition: REllipse.h:54
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
REllipse::endParam
double endParam
Getter function for this property: getEndParam Setter function for this property: setEndParam
Definition: REllipse.h:240
REllipseProxy.h
REllipseProxy
Proxy for advanced ellipse functionality.
Definition: REllipseProxy.h:38
RShape::getLength
virtual double getLength() const =0
REllipse::trimStartPoint
virtual bool trimStartPoint(double trimDist)
Definition: REllipse.h:171
REllipse::majorPoint
RVector majorPoint
Getter function for this property: getMajorPoint Setter function for this property: setMajorPoint
Definition: REllipse.h:225
RShape::move
virtual bool move(const RVector &offset)=0
RShape::getMiddlePoints
virtual QList< RVector > getMiddlePoints() const =0
RS::Side
Side
Side used for side of a point relative to an entity (right hand or left hand side)
Definition: RS.h:205
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RShape::getAngleAtPoint
virtual double getAngleAtPoint(const RVector &pos) const
Definition: RShape.h:249
RS::Ending
Ending
Entity ending.
Definition: RS.h:215
RS::FromStart
@ FromStart
Definition: RS.h:264
RShape::getVectorProperties
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:165
REllipse::ellipseProxy
static REllipseProxy * ellipseProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: REllipse.h:248
RShape::getCenterPoints
virtual QList< RVector > getCenterPoints() const =0
RLine.h
REllipse::reversed
bool reversed
Getter function for this property: isReversed Setter function for this property: setReversed
Definition: REllipse.h:245
REllipse::isDirected
virtual bool isDirected() const
Definition: REllipse.h:62
REllipse::center
RVector center
Getter function for this property: getCenter Setter function for this property: setCenter
Definition: REllipse.h:220
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
REllipse::startParam
double startParam
Getter function for this property: getStartParam Setter function for this property: setStartParam
Definition: REllipse.h:235
RShape::Type
Type
Definition: RShape.h:74
REllipse::getEllipseProxy
static REllipseProxy * getEllipseProxy()
Definition: REllipse.h:208
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 *)
REllipse::clone
virtual REllipse * clone() const
Definition: REllipse.h:58
RShape::getDirection1
virtual double getDirection1() const
Definition: RShape.h:271
REllipse::setEllipseProxy
static void setEllipseProxy(REllipseProxy *p)
Definition: REllipse.h:198
RShape::getDoubleProperties
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:167
RShape::getBoolProperties
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:168
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::getStartPoint
virtual RVector getStartPoint() const
Definition: RShape.h:283
RShape::mirror
virtual bool mirror(const RLine &axis)=0
REllipse
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:42
RShape::getPointsWithDistanceToEnd
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
REllipse::ratio
double ratio
Getter function for this property: getRatio Setter function for this property: setRatio
Definition: REllipse.h:230
RShape::setZ
virtual void setZ(double z)=0
RS::FromAny
@ FromAny
Start or end.
Definition: RS.h:266
RShape::getDirection2
virtual double getDirection2() const
Definition: RShape.h:274
RShape::print
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1759
REllipse::isParamWithinArc
bool isParamWithinArc(double a) const
Definition: REllipse.h:123
RShape::getMiddlePoint
virtual RVector getMiddlePoint() const
Definition: RShape.h:289
REllipse::isAngleWithinArc
bool isAngleWithinArc(double a) const
Definition: REllipse.h:117
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
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:263
RShape::getAngleAt
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:244
RShape::getOffsetShapes
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RShape.cpp:1941
RShape::getEndPoint
virtual RVector getEndPoint() const
Definition: RShape.h:286
REllipse::trimEndPoint
virtual bool trimEndPoint(double trimDist)
Definition: REllipse.h:174
RPolyline
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
REllipse::hasProxy
static bool hasProxy()
Definition: REllipse.h:191
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RSpline.h
RShape::rotate
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0