Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/findip.cpp
3206 views
1
// find inner point
2
3
#include <mystdlib.h>
4
#include "meshing.hpp"
5
6
namespace netgen
7
{
8
9
10
template <typename POINTARRAY, typename FACEARRAY>
11
int FindInnerPoint (POINTARRAY & points,
12
FACEARRAY & faces,
13
Point3d & p)
14
{
15
int i, j;
16
ARRAY<Vec3d> a;
17
ARRAY<double> c;
18
Point3d p1, pmin;
19
int i1, i2, i3, i4;
20
int nf;
21
DenseMatrix m(3), inv(3);
22
Vector rs(3), x(3);
23
double f, fmin, hd, hmax;
24
25
nf = faces.Size();
26
27
// testout << "#faces = " << faces.Size() << endl;
28
// testout << "#points = " << points.Size() << endl;
29
30
a.SetSize (nf);
31
c.SetSize (nf);
32
33
for (i = 1; i <= nf; i++)
34
{
35
p1 = points.Get(faces.Get(i).PNum(1));
36
a.Elem(i) = Cross (points.Get(faces.Get(i).PNum(2)) - points.Get(faces.Get(i).PNum(1)),
37
points.Get(faces.Get(i).PNum(3)) - points.Get(faces.Get(i).PNum(1)));
38
a.Elem(i) /= a.Get(i).Length();
39
c.Elem(i) = - (a.Get(i).X() * p1.X() + a.Get(i).Y() * p1.Y() + a.Get(i).Z() * p1.Z());
40
}
41
42
43
hmax = 0;
44
for (i = 1; i <= nf; i++)
45
{
46
const Element2d & el = faces.Get(i);
47
for (j = 1; j <= 3; j++)
48
{
49
double hi = Dist (points.Get(el.PNumMod(j)),
50
points.Get(el.PNumMod(j+1)));
51
if (hi > hmax) hmax = hi;
52
}
53
}
54
55
56
fmin = 100;
57
pmin = Point3d (0, 0, 0);
58
59
for (i1 = 1; i1 <= nf; i1++)
60
for (i2 = i1+1; i2 <= nf; i2++)
61
for (i3 = i2+1; i3 <= nf; i3++)
62
for (i4 = i3+1; i4 <= nf; i4++)
63
{
64
m.Elem(1, 1) = a.Get(i1).X() - a.Get(i2).X();
65
m.Elem(1, 2) = a.Get(i1).Y() - a.Get(i2).Y();
66
m.Elem(1, 3) = a.Get(i1).Z() - a.Get(i2).Z();
67
rs.Elem(1) = c.Get(i2) - c.Get(i1);
68
69
m.Elem(2, 1) = a.Get(i1).X() - a.Get(i3).X();
70
m.Elem(2, 2) = a.Get(i1).Y() - a.Get(i3).Y();
71
m.Elem(2, 3) = a.Get(i1).Z() - a.Get(i3).Z();
72
rs.Elem(2) = c.Get(i3) - c.Get(i1);
73
74
m.Elem(3, 1) = a.Get(i1).X() - a.Get(i4).X();
75
m.Elem(3, 2) = a.Get(i1).Y() - a.Get(i4).Y();
76
m.Elem(3, 3) = a.Get(i1).Z() - a.Get(i4).Z();
77
rs.Elem(3) = c.Get(i4) - c.Get(i1);
78
79
80
if (fabs (m.Det()) > 1e-10)
81
{
82
CalcInverse (m, inv);
83
inv.Mult (rs, x);
84
85
// testout << "x = " << x << endl;
86
87
88
f = -1e10;
89
for (i = 1; i <= nf; i++)
90
{
91
hd = x.Elem(1) * a.Get(i).X()
92
+ x.Elem(2) * a.Get(i).Y()
93
+ x.Elem(3) * a.Get(i).Z()
94
+ c.Get(i);
95
if (hd > f) f = hd;
96
}
97
98
if (f < fmin)
99
{
100
fmin = f;
101
pmin.X() = x.Elem(1);
102
pmin.Y() = x.Elem(2);
103
pmin.Z() = x.Elem(3);
104
}
105
}
106
}
107
108
// testout << "fmin = " << fmin << endl;
109
// testout << "pmin = " << pmin << endl;
110
111
p = pmin;
112
return (fmin < -1e-3 * hmax) ? 1 : 0;
113
// return (fmin < 0) ? 1 : 0;
114
}
115
}
116
117