Flow123d
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 (X1 != NULL) {
67  delete X1;
68  }
69  if (X2 != NULL) {
70  delete X2;
71  }
72  if (X3 != NULL) {
73  delete X3;
74  }*/
75 
76  if (A1 != NULL) {
77  delete A1;
78  }
79  if (A2 != NULL) {
80  delete A2;
81  }
82  if (A3 != NULL) {
83  delete A3;
84  }
85 
86  if (pl != NULL) {
87  delete pl;
88  }
89 }
90 
91 const TPlain &TTriangle::GetPlain() const {
92  return *pl;
93 }
94 
95 const TAbscissa &TTriangle::GetAbscissa(const int i) const {
96  switch (i) {
97  case 1: return *A1;
98  break;
99  case 2: return *A2;
100  break;
101  case 3: return *A3;
102  break;
103  default:
104  THROW( ExcAssertMsg() << EI_Message( "Unknown number of the abscissa of the triangle.") );
105 
106  }
107 }
108 
109 const TPoint &TTriangle::GetPoint(int i) const {
110  switch (i) {
111  case 1: return X1;
112  break;
113  case 2: return X2;
114  break;
115  case 3: return X3;
116  break;
117  default: THROW( ExcAssertMsg() << EI_Message( "Unknown number of the point of the triangle.") );
118  }
119 }
120 
121 void TTriangle::SetPoints(const TPoint& P1, const TPoint& P2, const TPoint& P3) {
122  X1 = P1;
123  X2 = P2;
124  X3 = P3;
125 
126  A1->SetPoints(P1, P2);
127  A2->SetPoints(P2, P3);
128  A3->SetPoints(P3, P1);
129 
130  pl->SetPoints(P1, P2, P3);
131 
132  ComputeArea();
133 }
134 
136  TVector N = Cross(A1->GetVector(), A2->GetVector());
137  area = 0.5 * N.Length();
138 }
139 
141  return area;
142 }
143 
145  arma::vec3 minCoor;
146  arma::vec3 maxCoor;
147 
148  for (int i=0; i<3; ++i) {
149  minCoor(i) = GetMin(i+1);
150  maxCoor(i) = GetMax(i+1);
151  }
152 
153  boundingBox=BoundingBox(minCoor, maxCoor);
154  return boundingBox;
155 }
156 
157 double TTriangle::GetMin(int i) const {
158  double min = X1.Get(i);
159 
160  if (X2.Get(i) < min) {
161  min = X2.Get(i);
162  }
163  if (X3.Get(i) < min) {
164  min = X3.Get(i);
165  }
166 
167  return min;
168 }
169 
170 double TTriangle::GetMax(int i) const {
171  double max = X1.Get(i);
172 
173  if (X2.Get(i) > max) {
174  max = X2.Get(i);
175  }
176  if (X3.Get(i) > max) {
177  max = X3.Get(i);
178  }
179 
180  return max;
181 }
182 
184  area = t.area;
185 
186  *(*this).A1 = *t.A1;
187  *(*this).A2 = *t.A2;
188  *(*this).A3 = *t.A3;
189  *(*this).pl = *t.pl;
190  X1 = t.X1;
191  X2 = t.X2;
192  X3 = t.X3;
193 
194  return *this;
195 }
196 
197 bool TTriangle::IsInner(const TPoint& P) const {
198  TVector N1, N2, U1(X1, X2), U2(X2, X3), U3(X3, X1);
199  TVector Up1(X1, P), Up2(X2, P), Up3(X3, P);
200 
201  N1 = Cross(Up1, U1);
202  N2 = Cross(U1, U3);
203  if (Dot(N1, N2) < 0) {
204  return false;
205  }
206 
207  N1 = Cross(Up2, U2);
208  N2 = Cross(U2, U1);
209  if (Dot(N1, N2) < 0) {
210  return false;
211  }
212 
213  N1 = Cross(Up3, U3);
214  N2 = Cross(U3, U2);
215  if (Dot(N1, N2) < 0) {
216  return false;
217  }
218 
219  return true;
220 }