KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
plane.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Nelson Lafontaine
11 //
12 
13 #if !defined(KRATOS_PLANE_H_INCLUDED )
14 #define KRATOS_PLANE_H_INCLUDED
15 
16 // System includes
17 #include <iostream>
18 
19 // External includes
20 #include "utilities/math_utils.h"
21 
22 
23 namespace Kratos
24 {
25 
26 // The plane is represented as Dot(N,X) = c where N is a unit-length
27 // normal vector, c is the plane constant, and X is any point on the
28 // plane. The user must ensure that the normal vector is unit length.
29 class Plane
30 {
31 public:
32 
34  {
38  mConstant = 0.00;
39  }
40 
41  ~Plane() {}
42 
43  //----------------------------------------------------------------------------
44  Plane(const array_1d<double, 3>& normal, double& constant):
45  mNormal(normal),
46  mConstant(constant)
47  {
48  }
49  //----------------------------------------------------------------------------
51  mNormal(normal)
52  {
53  mConstant = inner_prod(normal, p);
54  }
55  //----------------------------------------------------------------------------
57  const array_1d<double, 3>& p1,
58  const array_1d<double, 3>& p2)
59  {
60  array_1d<double, 3> edge1 = p1 - p0;
61  array_1d<double, 3> edge2 = p2 - p0;
62 
64 
66  }
67 
68 
70  {
71  array_1d<double, 3> edge1 = p1 - p0;
72  array_1d<double, 3> edge2 = p2 - p0;
73 
75 
77  }
78 
79  //----------------------------------------------------------------------------
82  {
83  return inner_prod(mNormal,p) - mConstant;
84  }
85 
88  array_1d<double, 3>& rPoint,
92  )
93  {
94  array_1d<double, 3> diff = p0 - rPoint;
95  array_1d<double, 3> edge0 = p1 - p0;
96  array_1d<double, 3> edge1 = p2 - p0;
97 
98  double a00 = inner_prod(edge0, edge0);
99  double a01 = inner_prod(edge0, edge1);
100  double a11 = inner_prod(edge1, edge1);
101  double b0 = inner_prod(diff, edge0);
102  double b1 = inner_prod(diff, edge1);
103  double c = inner_prod(diff, diff);
104  double det = std::fabs(a00*a11 - a01*a01);
105  double s = a01*b1 - a11*b0;
106  double t = a01*b0 - a00*b1;
107  double sqrDistance = 0.00;
108 
109  if (s + t <= det)
110  {
111  if (s < 0.00)
112  {
113  if (t < 0.00 ) // region 4
114  {
115  if (b0 < 0.00)
116  {
117  t = 0.00;
118  if (-b0 >= a00)
119  {
120  s = 1.00;
121  sqrDistance = a00 + (2.00)*b0 + c;
122  }
123  else
124  {
125  s = -b0/a00;
126  sqrDistance = b0*s + c;
127  }
128  }
129  else
130  {
131  s = 0.00;
132  if (b1 >= 0.00)
133  {
134  t = 0.00;
135  sqrDistance = c;
136  }
137  else if (-b1 >= a11)
138  {
139  t = 1.00;
140  sqrDistance = a11 + (2.00)*b1 + c;
141  }
142  else
143  {
144  t = -b1/a11;
145  sqrDistance = b1*t + c;
146  }
147  }
148  }
149  else // region 3
150  {
151  s = 0.00;
152  if (b1 >= 0.00)
153  {
154  t = 0.00;
155  sqrDistance = c;
156  }
157  else if (-b1 >= a11)
158  {
159  t = 1.00;
160  sqrDistance = a11 + (2.00)*b1 + c;
161  }
162  else
163  {
164  t = -b1/a11;
165  sqrDistance = b1*t + c;
166  }
167  }
168  }
169  else if (t < 0.00) // region 5
170  {
171  t = 0.00;
172  if (b0 >= 0.00)
173  {
174  s = 0.00;
175  sqrDistance = c;
176  }
177  else if (-b0 >= a00)
178  {
179  s = 1.00;
180  sqrDistance = a00 + (1.00)*b0 + c;
181  }
182  else
183  {
184  s = -b0/a00;
185  sqrDistance = b0*s + c;
186  }
187  }
188  else // region 0
189  {
190  // minimum at interior point
191  double invDet = (1.00)/det;
192  s *= invDet;
193  t *= invDet;
194  sqrDistance = s*(a00*s + a01*t + (2.00)*b0) +
195  t*(a01*s + a11*t + (2.00)*b1) + c;
196  }
197  }
198  else
199  {
200  double tmp0, tmp1, numer, denom;
201 
202  if (s < 0.00) // region 2
203  {
204  tmp0 = a01 + b0;
205  tmp1 = a11 + b1;
206  if (tmp1 > tmp0)
207  {
208  numer = tmp1 - tmp0;
209  denom = a00 - (2.00)*a01 + a11;
210  if (numer >= denom)
211  {
212  s = 1.00;
213  t = 0.00;
214  sqrDistance = a00 + (2.00)*b0 + c;
215  }
216  else
217  {
218  s = numer/denom;
219  t = 1.00 - s;
220  sqrDistance = s*(a00*s + a01*t + (2.00)*b0) +
221  t*(a01*s + a11*t + (2.00)*b1) + c;
222  }
223  }
224  else
225  {
226  s = 0.00;
227  if (tmp1 <= 0.00)
228  {
229  t = 1.00;
230  sqrDistance = a11 + (2.00)*b1 + c;
231  }
232  else if (b1 >= 0.00)
233  {
234  t = 0.00;
235  sqrDistance = c;
236  }
237  else
238  {
239  t = -b1/a11;
240  sqrDistance = b1*t + c;
241  }
242  }
243  }
244  else if (t < 0.00) // region 6
245  {
246  tmp0 = a01 + b1;
247  tmp1 = a00 + b0;
248  if (tmp1 > tmp0)
249  {
250  numer = tmp1 - tmp0;
251  denom = a00 - (2.00)*a01 + a11;
252  if (numer >= denom)
253  {
254  t = 1.00;
255  s = 0.00;
256  sqrDistance = a11 + (2.00)*b1 + c;
257  }
258  else
259  {
260  t = numer/denom;
261  s = 1.00 - t;
262  sqrDistance = s*(a00*s + a01*t + (2.00)*b0) +
263  t*(a01*s + a11*t + (2.00)*b1) + c;
264  }
265  }
266  else
267  {
268  t = 0.00;
269  if (tmp1 <= 0.00)
270  {
271  s = 1.00;
272  sqrDistance = a00 + (2.00)*b0 + c;
273  }
274  else if (b0 >= 0.00)
275  {
276  s = 0.00;
277  sqrDistance = c;
278  }
279  else
280  {
281  s = -b0/a00;
282  sqrDistance = b0*s + c;
283  }
284  }
285  }
286  else // region 1
287  {
288  numer = a11 + b1 - a01 - b0;
289  if (numer <= 0.00)
290  {
291  s = 0.00;
292  t = 1.00;
293  sqrDistance = a11 + (2.00)*b1 + c;
294  }
295  else
296  {
297  denom = a00 - (2.00)*a01 + a11;
298  if (numer >= denom)
299  {
300  s = 1.00;
301  t = 0.00;
302  sqrDistance = a00 + (2.00)*b0 + c;
303  }
304  else
305  {
306  s = numer/denom;
307  t = 1.00 - s;
308  sqrDistance = s*(a00*s + a01*t + (2.00)*b0) +
309  t*(a01*s + a11*t + (2.00)*b1) + c;
310  }
311  }
312  }
313  }
314 
315  // Account for numerical round-off error.
316  if (sqrDistance < 0.00)
317  {
318  sqrDistance = 0.00;
319  }
320 
321  //mClosestPoint0 = *mPoint;
322  mClosestPoint = p0 + s*edge0 + t*edge1;
323  mTriangleBary[0] = 1.00 - s - t;
324  mTriangleBary[1] = s;
325  mTriangleBary[2] = t;
326 
327  return sqrDistance;
328  }
329 
330 
331 
332  //----------------------------------------------------------------------------
334  {
335  double distance = DistanceTo(p);
336  if (distance < 0.00)
337  return -1;
338  else if (distance > 0.00)
339  return +1;
340  else
341  return 0;
342  }
343 
347  double mConstant;
348 };
349 }
350 #endif
351 
static void UnitCrossProduct(T1 &c, const T2 &a, const T3 &b)
Performs the unitary cross product of the two input vectors a,b.
Definition: math_utils.h:831
Definition: plane.h:30
array_1d< double, 3 > mNormal
Definition: plane.h:346
~Plane()
Definition: plane.h:41
Plane(const array_1d< double, 3 > &p0, const array_1d< double, 3 > &p1, const array_1d< double, 3 > &p2)
Definition: plane.h:56
double DistanceTo(const array_1d< double, 3 > &p)
Calcula la distancia del punto al plano.
Definition: plane.h:81
Plane(const array_1d< double, 3 > &normal, double &constant)
Definition: plane.h:44
double mConstant
Definition: plane.h:347
int WhichSide(const array_1d< double, 3 > &p)
Definition: plane.h:333
array_1d< double, 3 > mClosestPoint
Definition: plane.h:345
Plane(const array_1d< double, 3 > &normal, const array_1d< double, 3 > &p)
Definition: plane.h:50
double DistPoint3Triangle3(array_1d< double, 3 > &rPoint, array_1d< double, 3 > &p0, array_1d< double, 3 > &p1, array_1d< double, 3 > &p2)
computa la distancia de un punto a un triangulo 3D
Definition: plane.h:87
Plane()
Definition: plane.h:33
array_1d< double, 3 > mTriangleBary
Definition: plane.h:344
void AssignPointsAndComputeParameters(array_1d< double, 3 > &p0, array_1d< double, 3 > &p1, array_1d< double, 3 > &p2)
Definition: plane.h:69
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int t
Definition: ode_solve.py:392
p
Definition: sensitivityMatrix.py:52