Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/findip2.hpp
3206 views
// find inner point12template <typename POINTARRAY, typename FACEARRAY>3inline int FindInnerPoint2 (POINTARRAY & points,4FACEARRAY & faces,5Point3d & p)6{7static int timer = NgProfiler::CreateTimer ("FindInnerPoint2");8NgProfiler::RegionTimer reg (timer);910ARRAY<Vec3d> a;11ARRAY<double> c;12Mat<3> m, inv;13Vec<3> rs, x, pmin;1415int nf = faces.Size();1617a.SetSize (nf);18c.SetSize (nf);1920for (int i = 0; i < nf; i++)21{22Point3d p1 = points.Get(faces[i][0]);23a[i] = Cross (points.Get(faces[i][1]) - p1,24points.Get(faces[i][2]) - p1);25a[i] /= a[i].Length();26c[i] = - (a[i].X() * p1.X() + a[i].Y() * p1.Y() + a[i].Z() * p1.Z());27}282930x = 0;313233double hmax = 0;34for (int i = 0; i < nf; i++)35{36const Element2d & el = faces[i];37for (int j = 1; j <= 3; j++)38{39double hi = Dist (points.Get(el.PNumMod(j)),40points.Get(el.PNumMod(j+1)));41if (hi > hmax) hmax = hi;42}43}4445double fmin = 0;4647for (int i1 = 1; i1 <= nf; i1++)48for (int i2 = i1+1; i2 <= nf; i2++)49for (int i3 = i2+1; i3 <= nf; i3++)50for (int i4 = i3+1; i4 <= nf; i4++)51{52m(0, 0) = a.Get(i1).X() - a.Get(i2).X();53m(0, 1) = a.Get(i1).Y() - a.Get(i2).Y();54m(0, 2) = a.Get(i1).Z() - a.Get(i2).Z();55rs(0) = c.Get(i2) - c.Get(i1);5657m(1, 0) = a.Get(i1).X() - a.Get(i3).X();58m(1, 1) = a.Get(i1).Y() - a.Get(i3).Y();59m(1, 2) = a.Get(i1).Z() - a.Get(i3).Z();60rs(1) = c.Get(i3) - c.Get(i1);6162m(2, 0) = a.Get(i1).X() - a.Get(i4).X();63m(2, 1) = a.Get(i1).Y() - a.Get(i4).Y();64m(2, 2) = a.Get(i1).Z() - a.Get(i4).Z();65rs(2) = c.Get(i4) - c.Get(i1);666768if (fabs (Det (m)) > 1e-10)69{70CalcInverse (m, inv);71x = inv * rs;7273double f = -1e10;74for (int i = 0; i < nf; i++)75{76double hd =77x(0) * a[i].X() + x(1) * a[i].Y() + x(2) * a[i].Z() + c[i];78if (hd > f) f = hd;79if (hd > fmin) break;80}8182if (f < fmin)83{84fmin = f;85pmin = x;86}87}88}8990p = Point3d (pmin(0), pmin(1), pmin(2));91(*testout) << "fmin = " << fmin << endl;92return (fmin < -1e-3 * hmax);93}94959697