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