Flow123d  jenkins-Flow123d-windows-release-multijob-285
triangle.cpp
Go to the documentation of this file.
1 #include "system/exc_common.hh"
3 
4 
5 
7 
10 }
11 
13  id = generateId();
14 
15  A1 = new TAbscissa();
16  A2 = new TAbscissa();
17  A3 = new TAbscissa();
18 
19  pl = new TPlain();
20 
21  area = 0;
22 }
23 
25  id = generateId();
26 
27  X1 = T.X1;
28  X2 = T.X2;
29  X3 = T.X3;
30 
31  update();
32 }
33 
34 TTriangle::TTriangle(const TPoint& P1, const TPoint& P2, const TPoint& P3) {
35  id = generateId();
36 
37  X1 = P1;
38  X2 = P2;
39  X3 = P3;
40 
41  update();
42 }
43 
44 
46  id = generateId();
47 
48  X1=TPoint(ele.node[0]->point()(0), ele.node[0]->point()(1), ele.node[0]->point()(2));
49  X2=TPoint(ele.node[1]->point()(0), ele.node[1]->point()(1), ele.node[1]->point()(2));
50  X3=TPoint(ele.node[2]->point()(0), ele.node[2]->point()(1), ele.node[2]->point()(2));
51 
52  update();
53 }
54 
56  A1 = new TAbscissa(X1, X2);
57  A2 = new TAbscissa(X2, X3);
58  A3 = new TAbscissa(X3, X1);
59 
60  pl = new TPlain(X1, X2, X3);
61 
62  ComputeArea();
63 }
64 
66  if (A1 != NULL) {
67  delete A1;
68  }
69  if (A2 != NULL) {
70  delete A2;
71  }
72  if (A3 != NULL) {
73  delete A3;
74  }
75 
76  if (pl != NULL) {
77  delete pl;
78  }
79 }
80 
81 const TPlain &TTriangle::GetPlain() const {
82  return *pl;
83 }
84 
85 const TAbscissa &TTriangle::GetAbscissa(const int i) const {
86  switch (i) {
87  case 1: return *A1;
88  break;
89  case 2: return *A2;
90  break;
91  case 3: return *A3;
92  break;
93  default:
94  THROW( ExcAssertMsg() << EI_Message( "Unknown number of the abscissa of the triangle.") );
95 
96  }
97 }
98 
99 const TPoint &TTriangle::GetPoint(int i) const {
100  switch (i) {
101  case 1: return X1;
102  break;
103  case 2: return X2;
104  break;
105  case 3: return X3;
106  break;
107  default: THROW( ExcAssertMsg() << EI_Message( "Unknown number of the point of the triangle.") );
108  }
109 }
110 
111 void TTriangle::SetPoints(const TPoint& P1, const TPoint& P2, const TPoint& P3) {
112  X1 = P1;
113  X2 = P2;
114  X3 = P3;
115 
116  A1->SetPoints(P1, P2);
117  A2->SetPoints(P2, P3);
118  A3->SetPoints(P3, P1);
119 
120  pl->SetPoints(P1, P2, P3);
121 
122  ComputeArea();
123 }
124 
126  TVector N = Cross(A1->GetVector(), A2->GetVector());
127  area = 0.5 * N.Length();
128 }
129 
131  return area;
132 }
133 
135  arma::vec3 minCoor;
136  arma::vec3 maxCoor;
137 
138  for (int i=0; i<3; ++i) {
139  minCoor(i) = GetMin(i+1);
140  maxCoor(i) = GetMax(i+1);
141  }
142 
143  boundingBox=BoundingBox(minCoor, maxCoor);
144  return boundingBox;
145 }
146 
147 double TTriangle::GetMin(int i) const {
148  double min = X1.Get(i);
149 
150  if (X2.Get(i) < min) {
151  min = X2.Get(i);
152  }
153  if (X3.Get(i) < min) {
154  min = X3.Get(i);
155  }
156 
157  return min;
158 }
159 
160 double TTriangle::GetMax(int i) const {
161  double max = X1.Get(i);
162 
163  if (X2.Get(i) > max) {
164  max = X2.Get(i);
165  }
166  if (X3.Get(i) > max) {
167  max = X3.Get(i);
168  }
169 
170  return max;
171 }
172 
174  area = t.area;
175 
176  *(*this).A1 = *t.A1;
177  *(*this).A2 = *t.A2;
178  *(*this).A3 = *t.A3;
179  *(*this).pl = *t.pl;
180  X1 = t.X1;
181  X2 = t.X2;
182  X3 = t.X3;
183 
184  return *this;
185 }
186 
187 bool TTriangle::IsInner(const TPoint& P) const {
188  TVector N1, N2, U1(X1, X2), U2(X2, X3), U3(X3, X1);
189  TVector Up1(X1, P), Up2(X2, P), Up3(X3, P);
190 
191  N1 = Cross(Up1, U1);
192  N2 = Cross(U1, U3);
193  if (Dot(N1, N2) < 0) {
194  return false;
195  }
196 
197  N1 = Cross(Up2, U2);
198  N2 = Cross(U2, U1);
199  if (Dot(N1, N2) < 0) {
200  return false;
201  }
202 
203  N1 = Cross(Up3, U3);
204  N2 = Cross(U3, U2);
205  if (Dot(N1, N2) < 0) {
206  return false;
207  }
208 
209  return true;
210 }
TAbscissa * A1
Definition: triangle.h:19
const TVector & GetVector() const
Definition: bisector.cpp:87
Bounding box in 3d ambient space.
Definition: bounding_box.hh:55
double GetMin(int) const
Definition: triangle.cpp:147
static int numberInstance
Definition: triangle.h:12
void SetPoints(const TPoint &, const TPoint &)
Definition: abscissa.cpp:48
void ComputeArea()
Definition: triangle.cpp:125
TPoint X2
Definition: triangle.h:16
void SetPoints(const TPoint &, const TPoint &, const TPoint &)
Definition: plain.cpp:137
TPoint X3
Definition: triangle.h:17
Node ** node
Definition: elements.h:90
Definition: plain.h:7
int generateId()
Definition: triangle.cpp:8
double GetArea()
Definition: triangle.cpp:130
TTriangle & operator=(const TTriangle &t)
Definition: triangle.cpp:173
TPoint X1
Definition: triangle.h:15
bool IsInner(const TPoint &) const
Definition: triangle.cpp:187
const TPoint & GetPoint(int) const
Definition: triangle.cpp:99
Definition: point.h:10
void SetPoints(const TPoint &, const TPoint &, const TPoint &)
Definition: triangle.cpp:111
~TTriangle()
Definition: triangle.cpp:65
TVector Cross(const TVector &, const TVector &)
Definition: vector.cpp:163
BoundingBox & get_bounding_box()
Definition: triangle.cpp:134
double Get(int) const
Definition: point.cpp:103
double GetMax(int) const
Definition: triangle.cpp:160
const TPlain & GetPlain() const
Definition: triangle.cpp:81
double Length() const
Definition: vector.cpp:140
double area
Definition: triangle.h:27
TAbscissa * A3
Definition: triangle.h:21
TAbscissa * A2
Definition: triangle.h:20
BoundingBox boundingBox
Definition: triangle.h:25
const TAbscissa & GetAbscissa(int) const
Definition: triangle.cpp:85
void update()
Definition: triangle.cpp:55
arma::vec3 & point()
Definition: nodes.hh:80
TPlain * pl
Definition: triangle.h:23
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:34
double Dot(const TVector &, const TVector &)
Definition: vector.cpp:180