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 getShapeType() const {
53  return Triangle;
54  }
55 
56  virtual RTriangle* clone() const {
57  return new RTriangle(*this);
58  }
59 
60  virtual void setZ(double z);
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  virtual QList<RVector> getPointCloud(double segmentLength) const;
78 
79  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
80  virtual RVector getVectorTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
81  //virtual RVector getVectorTo(const RLine& line, bool limited = true) const;
82 
83  virtual RVector getNormal() const;
84 
85 // virtual bool intersectsWith(const RShape& other, bool limited) const;
86 
87 // virtual QList<RVector> getIntersectionPoints(const RShape& other,
88 // bool limited) const;
89 
90  bool isPointInTriangle(const RVector& p, bool treatAsQuadrant = false) const;
91  bool isPointInQuadrant(const RVector& p) const;
92 
93  double getD() const;
94 
95  virtual QList<QSharedPointer<RShape> > getExploded(int segments = RDEFAULT_MIN1) const;
96 
97  virtual bool move(const RVector& offset) {
98  corner[0].move(offset);
99  corner[1].move(offset);
100  corner[2].move(offset);
101  return true;
102  }
103  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR) {
104  corner[0].rotate(rotation, center);
105  corner[1].rotate(rotation, center);
106  corner[2].rotate(rotation, center);
107  return true;
108  }
109  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_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
RShape::getLength
virtual double getLength() const =0
RShape::Triangle
@ Triangle
Definition: RShape.h:83
RShape::getMiddlePoints
virtual QList< RVector > getMiddlePoints() const =0
RTriangle::getTransformed
QSharedPointer< RShape > getTransformed(const QTransform &transform) const
Definition: RTriangle.h:134
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RTriangle::getShapeType
virtual RShape::Type getShapeType() const
Definition: RTriangle.h:52
RShape::getVectorProperties
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:165
i
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: autostart.js:49
RShape::getCenterPoints
virtual QList< RVector > getCenterPoints() const =0
RLine.h
RTriangle::mirror
virtual bool mirror(const RLine &axis)
Definition: RTriangle.h:115
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RShape::Type
Type
Definition: RShape.h:74
RShape
Interface for geometrical shape classes.
Definition: RShape.h:72
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 *)
RTriangle::scale
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Definition: RTriangle.h:109
RTriangle::rotate
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Definition: RTriangle.h:103
RDEFAULT_MIN1
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RExplodable.h:30
RTriangle::clone
virtual RTriangle * clone() const
Definition: RTriangle.h:56
RShape::getPointCloud
virtual QList< RVector > getPointCloud(double segmentLength) const =0
RTriangle::flipVertical
virtual bool flipVertical()
Definition: RTriangle.h:127
RShape::getBoundingBox
virtual RBox getBoundingBox() const =0
RExplodable::getExploded
virtual QList< QSharedPointer< RShape > > getExploded(int segments=RDEFAULT_MIN1) const =0
RShape::getEndPoints
virtual QList< RVector > getEndPoints() const =0
RMAXDOUBLE
#define RMAXDOUBLE
Definition: RMath.h:63
RTriangle
Low-level mathematical representation of a triangle.
Definition: RTriangle.h:46
RTriangle::move
virtual bool move(const RVector &offset)
Definition: RTriangle.h:97
RShape::getPointsWithDistanceToEnd
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
RShape::setZ
virtual void setZ(double z)=0
RS::FromAny
@ FromAny
Start or end.
Definition: RS.h:266
RShape::print
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1759
RBox
Represents a box e.g.
Definition: RBox.h:43
RExplodable.h
RExplodable
Interface for explodable shape classes.
Definition: RExplodable.h:40
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RShape::getDistanceTo
virtual double getDistanceTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
Definition: RShape.cpp:48
RTriangle::flipHorizontal
virtual bool flipHorizontal()
Definition: RTriangle.h:121