Flow123d
tetrahedron.cpp
Go to the documentation of this file.
1 #include <cmath>
2 #include "system/exc_common.hh"
3 
7 
9 
12 }
13 
15  id = generateId();
16 
17  /*T1 = new TTriangle();
18  T2 = new TTriangle();
19  T3 = new TTriangle();
20  T4 = new TTriangle();*/
21 
22  A1 = new TAbscissa();
23  A2 = new TAbscissa();
24  A3 = new TAbscissa();
25  A4 = new TAbscissa();
26  A5 = new TAbscissa();
27  A6 = new TAbscissa();
28 
29  volume = 0.0;
30 }
31 
33  const TPoint& X3, const TPoint& X4) {
34  id = generateId();
35 
36  this->X1 = X1;
37  this->X2 = X2;
38  this->X3 = X3;
39  this->X4 = X4;
40 
41  T1.SetPoints(X2, X3, X4);
42  T2.SetPoints(X1, X3, X4);
43  T3.SetPoints(X1, X2, X4);
44  T4.SetPoints(X1, X2, X3);
45 
46  A1 = new TAbscissa(X1, X2);
47  A2 = new TAbscissa(X2, X3);
48  A3 = new TAbscissa(X3, X1);
49  A4 = new TAbscissa(X1, X4);
50  A5 = new TAbscissa(X2, X4);
51  A6 = new TAbscissa(X3, X4);
52 
53  ComputeVolume();
54 }
55 
57  /*delete X1;
58  delete X2;
59  delete X3;
60  delete X4;*/
61 
62  /*delete T1;
63  delete T2;
64  delete T3;
65  delete T4;*/
66 
67  delete A1;
68  delete A2;
69  delete A3;
70  delete A4;
71  delete A5;
72  delete A6;
73 }
74 
75 const TTriangle &TTetrahedron::GetTriangle(int i) const {
76  switch (i) {
77  case 1: return T1;
78  break;
79  case 2: return T2;
80  break;
81  case 3: return T3;
82  break;
83  case 4: return T4;
84  break;
85  default: THROW( ExcAssertMsg() << EI_Message("Unknown number of the triangle of the tetrahedron.") );
86  }
87 }
88 
89 const TAbscissa &TTetrahedron::GetAbscissa(int i) const {
90  switch (i) {
91  case 1: return *A1;
92  break;
93  case 2: return *A2;
94  break;
95  case 3: return *A3;
96  break;
97  case 4: return *A4;
98  break;
99  case 5: return *A5;
100  break;
101  case 6: return *A6;
102  break;
103  default: THROW( ExcAssertMsg() << EI_Message("Unknown number of the triangle of the tetrahedron.") );
104  }
105 }
106 
107 const TPoint &TTetrahedron::GetPoint(int i) const {
108  switch (i) {
109  case 1: return X1;
110  break;
111  case 2: return X2;
112  break;
113  case 3: return X3;
114  break;
115  case 4: return X4;
116  break;
117  default: THROW( ExcAssertMsg() << EI_Message("Unknown number of the point of the tetrahedron.") );
118  }
119 }
120 
121 double TTetrahedron::GetMin(int i) const {
122  double min = X1.Get(i);
123 
124  if (X2.Get(i) < min) {
125  min = X2.Get(i);
126  }
127  if (X3.Get(i) < min) {
128  min = X3.Get(i);
129  }
130  if (X4.Get(i) < min) {
131  min = X4.Get(i);
132  }
133 
134  return min;
135 }
136 
137 double TTetrahedron::GetMax(int i) const {
138  double max = X1.Get(i);
139 
140  if (X2.Get(i) > max) {
141  max = X2.Get(i);
142  }
143  if (X3.Get(i) > max) {
144  max = X3.Get(i);
145  }
146  if (X4.Get(i) > max) {
147  max = X4.Get(i);
148  }
149 
150  return max;
151 }
152 
154  return volume;
155 }
156 
158  double a[ 3 ][ 3 ];
159 
160  a[ 0 ][ 0 ] = X2.X() - X1.X();
161  a[ 0 ][ 1 ] = X2.Y() - X1.Y();
162  a[ 0 ][ 2 ] = X2.Z() - X1.Z();
163  a[ 1 ][ 0 ] = X3.X() - X1.X();
164  a[ 1 ][ 1 ] = X3.Y() - X1.Y();
165  a[ 1 ][ 2 ] = X3.Z() - X1.Z();
166  a[ 2 ][ 0 ] = X4.X() - X1.X();
167  a[ 2 ][ 1 ] = X4.Y() - X1.Y();
168  a[ 2 ][ 2 ] = X4.Z() - X1.Z();
169 
170  volume = fabs(Determinant3(a)) / 6.0;
171 }
172 
173 void TTetrahedron::SetPoints(const TPoint& P1, const TPoint& P2, const TPoint& P3, const TPoint& P4) {
174  X1 = P1;
175  X2 = P2;
176  X3 = P3;
177  X4 = P4;
178 
179  T1.SetPoints(P2, P3, P4);
180  T2.SetPoints(P1, P3, P4);
181  T3.SetPoints(P1, P2, P4);
182  T4.SetPoints(P1, P2, P3);
183 
184  A1->SetPoints(P1, P2);
185  A2->SetPoints(P2, P3);
186  A3->SetPoints(P3, P1);
187  A4->SetPoints(P1, P4);
188  A5->SetPoints(P2, P4);
189  A6->SetPoints(P3, P4);
190 
191  ComputeVolume();
192 }
193 
194 bool TTetrahedron::IsInner(const TPoint& P) const {
195  TVector N, U1(X1, X2), U2(X1, X3), U3(X1, X4), U4(X2, X3), U5(X2, X4), U6(X2, X1);
196  TVector Up1(X1, P), Up2(X2, P);
197 
198  N = Cross(U1, U2); //X4 is on opposite side of plain X1,X2,X3 than P
199  if (Dot(N, U3) * Dot(N, Up1) < 0) {
200  return false;
201  }
202 
203  N = Cross(U1, U3); //X3 x P
204  if (Dot(N, U2) * Dot(N, Up1) < 0) {
205  return false;
206  }
207 
208  N = Cross(U2, U3); //X2 x P
209  if (Dot(N, U1) * Dot(N, Up1) < 0) {
210  return false;
211  }
212 
213  N = Cross(U4, U5); //X1 x P
214  if (Dot(N, U6) * Dot(N, Up2) < 0) {
215  return false;
216  }
217 
218  return true;
219 }