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 
63  static RTriangle createArrow(const RVector& position, double direction, double size);
64 
65  virtual RBox getBoundingBox() const;
66  virtual double getLength() const;
67  double getArea() const;
68  RVector getCorner(int i) const;
69  void setCorner(int i, const RVector& p);
70 
71  virtual QList<RVector> getEndPoints() const;
72  virtual QList<RVector> getMiddlePoints() const;
73  virtual QList<RVector> getCenterPoints() const;
74  virtual QList<RVector> getPointsWithDistanceToEnd(
75  double distance, RS::From from = RS::FromAny) const;
76 
77  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
78  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
79  //virtual RVector getVectorTo(const RLine& line, bool limited = true) const;
80 
81  virtual RVector getNormal() const;
82 
83 // virtual bool intersectsWith(const RShape& other, bool limited) const;
84 
85 // virtual QList<RVector> getIntersectionPoints(const RShape& other,
86 // bool limited) const;
87 
88  bool isPointInTriangle(const RVector& p, bool treatAsQuadrant = false) const;
89  bool isPointInQuadrant(const RVector& p) const;
90 
91  double getD() const;
92 
93  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
94 
95  virtual bool move(const RVector& offset) {
96  corner[0].move(offset);
97  corner[1].move(offset);
98  corner[2].move(offset);
99  return true;
100  }
101  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
102  corner[0].rotate(rotation, center);
103  corner[1].rotate(rotation, center);
104  corner[2].rotate(rotation, center);
105  return true;
106  }
107  virtual bool scale(const RVector& scaleFactors, const RVector& center =
108  RVector()) {
109  corner[0].scale(scaleFactors, center);
110  corner[1].scale(scaleFactors, center);
111  corner[2].scale(scaleFactors, center);
112  return true;
113  }
114  virtual bool mirror(const RLine& axis) {
115  corner[0].mirror(axis);
116  corner[1].mirror(axis);
117  corner[2].mirror(axis);
118  return true;
119  }
120  virtual bool flipHorizontal() {
121  corner[0].flipHorizontal();
122  corner[1].flipHorizontal();
123  corner[2].flipHorizontal();
124  return true;
125  }
126  virtual bool flipVertical() {
127  corner[0].flipVertical();
128  corner[1].flipVertical();
129  corner[2].flipVertical();
130  return true;
131  }
132 
133  QSharedPointer<RShape> getTransformed(const QTransform& transform) const {
134  return QSharedPointer<RShape>(
135  new RTriangle(
136  corner[0].getTransformed2d(transform),
137  corner[1].getTransformed2d(transform),
138  corner[2].getTransformed2d(transform)
139  )
140  );
141  }
142 
143 protected:
144  virtual void print(QDebug dbg) const;
145 
146 public:
147  RVector corner[3];
148 };
149 
150 Q_DECLARE_METATYPE(QList<RTriangle>)
154 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>)
155 Q_DECLARE_METATYPE(QSharedPointer<RTriangle>*)
156 
157 #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:107
virtual QList< RVector > getEndPoints() const =0
virtual bool flipHorizontal()
Definition: RTriangle.h:120
Low-level mathematical representation of a triangle.
Definition: RTriangle.h:46
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual double getLength() const =0
virtual RBox getBoundingBox() const =0
virtual bool mirror(const RLine &axis)
Definition: RTriangle.h:114
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: RTriangle.h:101
Start or end.
Definition: RS.h:201
virtual bool flipVertical()
Definition: RTriangle.h:126
virtual RShape::Type getType() const
Definition: RTriangle.h:52
QSharedPointer< RShape > getTransformed(const QTransform &transform) const
Definition: RTriangle.h:133
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny) const =0
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:43
Low-level mathematical representation of a line.
Definition: RLine.h:42
virtual bool move(const RVector &offset)
Definition: RTriangle.h:95
#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
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:198
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
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
virtual RTriangle * clone() const
Definition: RTriangle.h:56