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