find point in quad surface-element

This commit is contained in:
Joachim Schöberl 2016-05-09 12:54:08 +02:00
parent 1337786e73
commit 3226d8c2c2

View File

@ -4159,6 +4159,32 @@ namespace netgen
}
int SolveLinearSystemLS (const Vec3d & col1,
const Vec3d & col2,
const Vec3d & rhs,
Vec2d & sol)
{
double a11 = col1 * col1;
double a12 = col1 * col2;
double a22 = col2 * col2;
double det = a11 * a22 - a12 * a12;
if (det*det <= 1e-24 * a11 * a22)
{
sol = Vec2d (0, 0);
return 1;
}
Vec2d aTrhs;
aTrhs.X() = col1*rhs;
aTrhs.Y() = col2*rhs;
sol.X() = ( a22 * aTrhs.X() - a12 * aTrhs.Y()) / det;
sol.Y() = (-a12 * aTrhs.X() + a11 * aTrhs.Y()) / det;
return 0;
}
bool Mesh :: PointContainedIn2DElement(const Point3d & p,
double lami[3],
@ -4175,6 +4201,7 @@ namespace netgen
//SZ
if(SurfaceElement(element).GetType()==QUAD)
{
// cout << "check quad element" << endl;
const Element2d & el = SurfaceElement(element);
const Point3d & p1 = Point(el.PNum(1));
@ -4198,13 +4225,21 @@ namespace netgen
lami[2]=0.;
double eps = 1.E-12;
if(fabs(d.X()) <= eps && fabs(d.Y())<= eps)
// if(fabs(d.X()) <= eps && fabs(d.Y())<= eps)
if (d.Length2() < sqr(eps))
{
//Solve Linear System
Vec2d sol;
SolveLinearSystemLS (b, c, p-a, sol);
lami[0] = sol.X();
lami[1] = sol.Y();
/*
lami[0]=(c.Y()*(p.X()-a.X())-c.X()*(p.Y()-a.Y()))/
(b.X()*c.Y() -b.Y()*c.X());
lami[1]=(-b.Y()*(p.X()-a.X())+b.X()*(p.Y()-a.Y()))/
(b.X()*c.Y() -b.Y()*c.X());
*/
}
else
if(fabs(dxb) <= eps)
@ -4252,6 +4287,7 @@ namespace netgen
lami[1] = (-c1 - sqrt(rt))/2/c2;
lami[0] = (dxp - dxa -dxc*lami[1])/dxb;
}
// cout << "lam0,1 = " << lami[0] << ", " << lami[1] << endl;
if( lami[0] <= 1.+eps && lami[0] >= -eps && lami[1]<=1.+eps && lami[1]>=-eps)
{
@ -4713,6 +4749,16 @@ namespace netgen
}
}
Array<int> faces2;
topology->GetElementFaces(velement,faces2);
/*
cout << "no matching surf element" << endl
<< "p = " << p << endl
<< "faces-orig = " << faces2 << endl
<< "faces = " << faces << endl
<< ", vol el = " << velement
<< ", vlam = " << vlam[0] << "," << vlam[1] << "," << vlam[2] << endl;
*/
}
return 0;