Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/findip.cpp
3206 views
// find inner point12#include <mystdlib.h>3#include "meshing.hpp"45namespace netgen6{789template <typename POINTARRAY, typename FACEARRAY>10int FindInnerPoint (POINTARRAY & points,11FACEARRAY & faces,12Point3d & p)13{14int i, j;15ARRAY<Vec3d> a;16ARRAY<double> c;17Point3d p1, pmin;18int i1, i2, i3, i4;19int nf;20DenseMatrix m(3), inv(3);21Vector rs(3), x(3);22double f, fmin, hd, hmax;2324nf = faces.Size();2526// testout << "#faces = " << faces.Size() << endl;27// testout << "#points = " << points.Size() << endl;2829a.SetSize (nf);30c.SetSize (nf);3132for (i = 1; i <= nf; i++)33{34p1 = points.Get(faces.Get(i).PNum(1));35a.Elem(i) = Cross (points.Get(faces.Get(i).PNum(2)) - points.Get(faces.Get(i).PNum(1)),36points.Get(faces.Get(i).PNum(3)) - points.Get(faces.Get(i).PNum(1)));37a.Elem(i) /= a.Get(i).Length();38c.Elem(i) = - (a.Get(i).X() * p1.X() + a.Get(i).Y() * p1.Y() + a.Get(i).Z() * p1.Z());39}404142hmax = 0;43for (i = 1; i <= nf; i++)44{45const Element2d & el = faces.Get(i);46for (j = 1; j <= 3; j++)47{48double hi = Dist (points.Get(el.PNumMod(j)),49points.Get(el.PNumMod(j+1)));50if (hi > hmax) hmax = hi;51}52}535455fmin = 100;56pmin = Point3d (0, 0, 0);5758for (i1 = 1; i1 <= nf; i1++)59for (i2 = i1+1; i2 <= nf; i2++)60for (i3 = i2+1; i3 <= nf; i3++)61for (i4 = i3+1; i4 <= nf; i4++)62{63m.Elem(1, 1) = a.Get(i1).X() - a.Get(i2).X();64m.Elem(1, 2) = a.Get(i1).Y() - a.Get(i2).Y();65m.Elem(1, 3) = a.Get(i1).Z() - a.Get(i2).Z();66rs.Elem(1) = c.Get(i2) - c.Get(i1);6768m.Elem(2, 1) = a.Get(i1).X() - a.Get(i3).X();69m.Elem(2, 2) = a.Get(i1).Y() - a.Get(i3).Y();70m.Elem(2, 3) = a.Get(i1).Z() - a.Get(i3).Z();71rs.Elem(2) = c.Get(i3) - c.Get(i1);7273m.Elem(3, 1) = a.Get(i1).X() - a.Get(i4).X();74m.Elem(3, 2) = a.Get(i1).Y() - a.Get(i4).Y();75m.Elem(3, 3) = a.Get(i1).Z() - a.Get(i4).Z();76rs.Elem(3) = c.Get(i4) - c.Get(i1);777879if (fabs (m.Det()) > 1e-10)80{81CalcInverse (m, inv);82inv.Mult (rs, x);8384// testout << "x = " << x << endl;858687f = -1e10;88for (i = 1; i <= nf; i++)89{90hd = x.Elem(1) * a.Get(i).X()91+ x.Elem(2) * a.Get(i).Y()92+ x.Elem(3) * a.Get(i).Z()93+ c.Get(i);94if (hd > f) f = hd;95}9697if (f < fmin)98{99fmin = f;100pmin.X() = x.Elem(1);101pmin.Y() = x.Elem(2);102pmin.Z() = x.Elem(3);103}104}105}106107// testout << "fmin = " << fmin << endl;108// testout << "pmin = " << pmin << endl;109110p = pmin;111return (fmin < -1e-3 * hmax) ? 1 : 0;112// return (fmin < 0) ? 1 : 0;113}114}115116117