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