QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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
31class RBox;
32class RPolyline;
33
44public:
45 REllipse();
46 REllipse(const RVector& center,
47 const RVector& majorPoint,
48 double ratio,
49 double startParam, double endParam,
50 bool reversed);
51 virtual ~REllipse();
52
53 static REllipse createInscribed(const RVector& p1, const RVector& p2, const RVector& p3, const RVector& p4, const RVector& centerHint = RVector::invalid);
54 static REllipse createFrom4Points(const RVector& p1, const RVector& p2, const RVector& p3, const RVector& p4);
55
56 virtual RShape::Type getShapeType() const {
57 return Ellipse;
58 }
59
60 virtual QSharedPointer<RShape> clone() const {
61 return QSharedPointer<RShape>(new REllipse(*this));
62 }
63
64 QSharedPointer<REllipse> cloneToEllipse() const {
65 return QSharedPointer<REllipse>(new REllipse(*this));
66 }
67
68 virtual bool isDirected() const {
69 return true;
70 }
71
72 virtual bool isValid() const;
73
74 virtual void setZ(double z);
75
76 virtual QList<RVector> getVectorProperties() const;
77 virtual QList<double> getDoubleProperties() const;
78 virtual QList<bool> getBoolProperties() const;
79
80 virtual RBox getBoundingBox() const;
81
82 virtual QList<RVector> getEndPoints() const;
83 virtual QList<RVector> getMiddlePoints() const;
84 virtual QList<RVector> getCenterPoints() const;
85 virtual QList<RVector> getPointsWithDistanceToEnd(
86 double distance, int from = RS::FromAny) const;
87 virtual QList<RVector> getPointCloud(double segmentLength) const;
88
89 virtual RVector getVectorTo(const RVector& point,
90 bool limited = true, double strictRange = RMAXDOUBLE) const;
91
92 void moveStartPoint(const RVector& pos, bool changeAngleOnly=false);
93 void moveEndPoint(const RVector& pos, bool changeAngleOnly=false);
94
95 QList<RVector> getFoci() const;
96
97 RVector getCenter() const;
98 void setCenter(const RVector& vector);
99 RVector getMajorPoint() const;
100 RVector getMinorPoint() const;
101 void setMajorPoint(const RVector& vector);
102 void setMinorPoint(const RVector &p);
103 bool switchMajorMinor();
104 double getRatio() const;
105 void setRatio(double radius);
106
107 double getStartParam() const;
108 void setStartParam(double startParam);
109
110 double getEndParam() const;
111 void setEndParam(double endParam);
112
113 double getStartAngle() const;
114 void setStartAngle(double a);
115
116 double angleToParam(double a) const;
117
118 double getEndAngle() const;
119 void setEndAngle(double a);
120
121 double getAngleLength(bool allowForZeroLength = false) const;
122
123 bool isAngleWithinArc(double a) const {
124 if (isFullEllipse()) {
125 return true;
126 }
127 return RMath::isAngleBetween(a, getStartAngle(), getEndAngle(), reversed);
128 }
129 bool isParamWithinArc(double a) const {
130 if (isFullEllipse()) {
131 return true;
132 }
133 return RMath::isAngleBetween(a, getStartParam(), getEndParam(), reversed);
134 }
135
136 bool isReversed() const;
137 void setReversed(bool reversed);
138
139 virtual double getDirection1() const;
140 virtual double getDirection2() const;
141
142 virtual RS::Side getSideOfPoint(const RVector& point) const;
143
144 virtual RVector getStartPoint() const;
145 virtual RVector getEndPoint() const;
146 double getMajorRadius() const;
147 double getMinorRadius() const;
148 double getAngle() const;
149 void setAngle(double a);
150 bool isFullEllipse() const;
151 bool isCircular() const;
152 double getLength() const;
153 double getSimpsonLength(double f1, double f2) const;
154
155 bool contains(const RVector& p) const;
156
157 virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
158
159 double getAngleAtPoint(const RVector& pos) const;
160 double getParamTo(const RVector& pos) const;
161 double getRadiusAt(double param) const;
162 RVector getPointAt(double param) const;
163 RVector getMiddlePoint() const;
164
165 virtual RVector getPointOnShape() const;
166
167 virtual bool move(const RVector& offset);
168 virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
169 virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
170 virtual bool mirror(const RLine& axis);
171
172 virtual bool reverse();
173
174 virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
175
176 virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
177 virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
178 virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
179 virtual bool trimStartPoint(double trimDist) {
180 return RShape::trimStartPoint(trimDist);
181 }
182 virtual bool trimEndPoint(double trimDist) {
183 return RShape::trimEndPoint(trimDist);
184 }
185
186 void correctMajorMinor();
187 double getSweep() const;
188
189 QList<RVector> getBoxCorners();
190
191 QList<RLine> getTangents(const RVector& point) const;
192 RVector getTangentPoint(const RLine& line) const;
193
194 QList<RSpline> approximateWithSplines() const;
195 RPolyline approximateWithArcs(int segments) const;
196
197 virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
198 virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
199
200 static bool hasProxy() {
201 return ellipseProxy!=NULL;
202 }
203
208 if (ellipseProxy!=NULL) {
209 delete ellipseProxy;
210 }
211 ellipseProxy = p;
212 }
213
218 return ellipseProxy;
219 }
220
221#if QT_VERSION >= 0x060000
226 REllipse copy() const {
227 return *this;
228 }
229#endif
230
231protected:
232 virtual void print(QDebug dbg) const;
233
234public:
249 double ratio;
259 double endParam;
265
266private:
268};
269
273Q_DECLARE_METATYPE(QSharedPointer<REllipse>)
274Q_DECLARE_METATYPE(QSharedPointer<REllipse>*)
275
276#endif
Q_DECLARE_METATYPE(RMath *)
#define RMAXDOUBLE
Definition RMath.h:66
#define RDEFAULT_RVECTOR
Definition RVector.h:38
Represents a box e.g.
Definition RBox.h:46
Low-level mathematical representation of an ellipse or ellipse arc.
Definition REllipse.h:43
double startParam
Getter function for this property: getStartParam Setter function for this property: setStartParam
Definition REllipse.h:254
double ratio
Getter function for this property: getRatio Setter function for this property: setRatio
Definition REllipse.h:249
virtual RShape::Type getShapeType() const
Definition REllipse.h:56
RVector majorPoint
Getter function for this property: getMajorPoint Setter function for this property: setMajorPoint
Definition REllipse.h:244
RVector center
Getter function for this property: getCenter Setter function for this property: setCenter
Definition REllipse.h:239
double endParam
Getter function for this property: getEndParam Setter function for this property: setEndParam
Definition REllipse.h:259
bool reversed
Getter function for this property: isReversed Setter function for this property: setReversed
Definition REllipse.h:264
virtual bool isDirected() const
Definition REllipse.h:68
static void setEllipseProxy(REllipseProxy *p)
Definition REllipse.h:207
virtual QSharedPointer< RShape > clone() const
Definition REllipse.h:60
virtual bool trimStartPoint(double trimDist)
Definition REllipse.h:179
static REllipseProxy * getEllipseProxy()
Definition REllipse.h:217
QSharedPointer< REllipse > cloneToEllipse() const
Definition REllipse.h:64
static bool hasProxy()
Definition REllipse.h:200
static REllipseProxy * ellipseProxy
Copyright (c) 2011-2018 by Andrew Mustun.
Definition REllipse.h:267
virtual bool trimEndPoint(double trimDist)
Definition REllipse.h:182
bool isAngleWithinArc(double a) const
Definition REllipse.h:123
bool isParamWithinArc(double a) const
Definition REllipse.h:129
Proxy for advanced ellipse functionality.
Definition REllipseProxy.h:40
Low-level mathematical representation of a line.
Definition RLine.h:41
static bool isAngleBetween(double a, double a1, double a2, bool reversed)
Tests if angle a is between a1 and a2.
Definition RMath.cpp:683
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
From
End used to specify from which end of a shape to measure a distance.
Definition RS.h:371
@ FromStart
Definition RS.h:372
@ FromAny
Start or end.
Definition RS.h:374
Side
Side used for side of a point relative to an entity (right hand or left hand side)
Definition RS.h:313
Ending
Entity ending.
Definition RS.h:323
Interface for geometrical shape classes.
Definition RShape.h:72
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition RShape.cpp:2061
virtual bool isValid() const
Definition RShape.h:92
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
virtual QList< RVector > getPointCloud(double segmentLength) const =0
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition RShape.h:309
virtual RVector getStartPoint() const
Definition RShape.h:289
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
virtual RVector getEndPoint() const
Definition RShape.h:292
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition RShape.h:328
Type
Definition RShape.h:74
@ Ellipse
Definition RShape.h:80
virtual QList< RVector > getCenterPoints() const =0
virtual bool move(const RVector &offset)=0
virtual QList< double > getDoubleProperties() const
Definition RShape.h:172
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition RShape.h:249
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
virtual void print(QDebug dbg) const
Definition RShape.cpp:1760
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition RShape.cpp:2234
virtual bool mirror(const RLine &axis)=0
virtual double getDirection1() const
Definition RShape.h:277
virtual QList< RVector > getEndPoints() const =0
virtual RVector getMiddlePoint() const
Definition RShape.h:295
virtual double getAngleAtPoint(const RVector &pos) const
Definition RShape.h:254
virtual double getDirection2() const
Definition RShape.h:280
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition RShape.h:284
virtual QList< RVector > getVectorProperties() const
Definition RShape.h:170
virtual QList< RVector > getMiddlePoints() const =0
virtual RVector getPointOnShape() const
Definition RShape.cpp:174
virtual bool reverse()
Definition RShape.h:299
virtual void setZ(double z)=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
virtual RBox getBoundingBox() const =0
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition RShape.h:345
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition RShape.cpp:1756
virtual QList< bool > getBoolProperties() const
Definition RShape.h:173
virtual double getLength() const =0
Represents a 3d vector (x/y/z).
Definition RVector.h:47
static const RVector invalid
invalid vector
Definition RVector.h:335
#define QCADCORE_EXPORT
Definition core_global.h:10
#define NULL
Definition opennurbs_system.h:256