QCAD
Open Source 2D CAD
RTriangle.h
Go to the documentation of this file.
1 
20 #ifndef RTRIANGLE_H
21 #define RTRIANGLE_H
22 
23 #include "../core_global.h"
24 
25 #include "RExplodable.h"
26 #include "RShape.h"
27 #include "RVector.h"
28 #include "RLine.h"
29 
30 class RBox;
31 
32 #ifndef RDEFAULT_MIN1
33 #define RDEFAULT_MIN1 -1
34 #endif
35 
36 
47 public:
48  RTriangle();
49  RTriangle(const RVector& p1, const RVector& p2, const RVector& p3);
50  virtual ~RTriangle();
51 
52  virtual RShape::Type getType() const {
53  return Triangle;
54  }
55 
56  virtual RTriangle* clone() const {
57  return new RTriangle(*this);
58  }
59 
60  virtual void to2D();
61 
62  virtual QList<RVector> getVectorProperties() const;
63 
64  static RTriangle createArrow(const RVector& position, double direction, double size);
65 
66  virtual RBox getBoundingBox() const;
67  virtual double getLength() const;
68  double getArea() const;
69  RVector getCorner(int i) const;
70  void setCorner(int i, const RVector& p);
71 
72  virtual QList<RVector> getEndPoints() const;
73  virtual QList<RVector> getMiddlePoints() const;
74  virtual QList<RVector> getCenterPoints() const;
75  virtual QList<RVector> getPointsWithDistanceToEnd(
76  double distance, int from = RS::FromAny) const;
77 
78  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
79  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
80  //virtual RVector getVectorTo(const RLine& line, bool limited = true) const;
81 
82  virtual RVector getNormal() const;
83 
84 // virtual bool intersectsWith(const RShape& other, bool limited) const;
85 
86 // virtual QList<RVector> getIntersectionPoints(const RShape& other,
87 // bool limited) const;
88 
89  bool isPointInTriangle(const RVector& p, bool treatAsQuadrant = false) const;
90  bool isPointInQuadrant(const RVector& p) const;
91 
92  double getD() const;
93 
94  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
95 
96  virtual bool move(const RVector& offset) {
97  corner[0].move(offset);
98  corner[1].move(offset);
99  corner[2].move(offset);
100  return true;
101  }
102  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
103  corner[0].rotate(rotation, center);
104  corner[1].rotate(rotation, center);
105  corner[2].rotate(rotation, center);
106  return true;
107  }
108  virtual bool scale(const RVector& scaleFactors, const RVector& center =
109  RVector()) {
110  corner[0].scale(scaleFactors, center);
111  corner[1].scale(scaleFactors, center);
112  corner[2].scale(scaleFactors, center);
113  return true;
114  }
115  virtual bool mirror(const RLine& axis) {
116  corner[0].mirror(axis);
117  corner[1].mirror(axis);
118  corner[2].mirror(axis);
119  return true;
120  }
121  virtual bool flipHorizontal() {
122  corner[0].flipHorizontal();
123  corner[1].flipHorizontal();
124  corner[2].flipHorizontal();
125  return true;
126  }
127  virtual bool flipVertical() {
128  corner[0].flipVertical();
129  corner[1].flipVertical();
130  corner[2].flipVertical();
131  return true;
132  }
133 
134  QSharedPointer<RShape> getTransformed(const QTransform& transform) const {
135  return QSharedPointer<RShape>(
136  new RTriangle(
137  corner[0].getTransformed2D(transform),
138  corner[1].getTransformed2D(transform),
139  corner[2].getTransformed2D(transform)
140  )
141  );
142  }
143 
144 protected:
145  virtual void print(QDebug dbg) const;
146 
147 public:
148  RVector corner[3];
149 };
150 
151 Q_DECLARE_METATYPE(QList<RTriangle>)
155 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>)
156 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>*)
157 
158 #endif
Represents a box e.g.
Definition: RBox.h:43
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 scale(const RVector &scaleFactors, const RVector &center=RVector())
Definition: RTriangle.h:108
virtual QList< RVector > getEndPoints() const =0
virtual bool flipHorizontal()
Definition: RTriangle.h:121
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:141
Low-level mathematical representation of a triangle.
Definition: RTriangle.h:46
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
virtual bool mirror(const RLine &axis)
Definition: RTriangle.h:115
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: RTriangle.h:102
Start or end.
Definition: RS.h:203
virtual bool flipVertical()
Definition: RTriangle.h:127
virtual RShape::Type getType() const
Definition: RTriangle.h:52
QSharedPointer< RShape > getTransformed(const QTransform &transform) const
Definition: RTriangle.h:134
Q_DECLARE_METATYPE(RMath *)
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
virtual QList< RVector > getMiddlePoints() const =0
Type
Definition: RShape.h:54
#define RMAXDOUBLE
Definition: RMath.h:63
virtual double getDistanceTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition: RShape.cpp:47
Low-level mathematical representation of a line.
Definition: RLine.h:41
virtual bool move(const RVector &offset)
Definition: RTriangle.h:96
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RExplodable.h:30
Interface for explodable shape classes.
Definition: RExplodable.h:40
Definition: RShape.h:63
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1719
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual RTriangle * clone() const
Definition: RTriangle.h:56