mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 14:10:34 +05:00
VecInSolid, poly
This commit is contained in:
parent
54dba89dd8
commit
4f4483794d
@ -168,9 +168,7 @@ void Polyhedra :: GetTangentialSurfaceIndices (const Point<3> & p,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OLDVECINSOLD
|
INSOLID_TYPE Polyhedra :: VecInSolidOld (const Point<3> & p,
|
||||||
#ifdef OLDVECINSOLD
|
|
||||||
INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
|
||||||
const Vec<3> & v,
|
const Vec<3> & v,
|
||||||
double eps) const
|
double eps) const
|
||||||
{
|
{
|
||||||
@ -240,13 +238,12 @@ INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
|
||||||
// check how many faces a ray starting in p+alpha*v intersects
|
// check how many faces a ray starting in p+alpha*v intersects
|
||||||
INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
INSOLID_TYPE Polyhedra :: VecInSolidNew (const Point<3> & p,
|
||||||
const Vec<3> & v,
|
const Vec<3> & v,
|
||||||
double eps) const
|
double eps, bool printing) const
|
||||||
{
|
{
|
||||||
if (!poly_bbox.IsIn (p, eps))
|
if (!poly_bbox.IsIn (p, eps))
|
||||||
return IS_OUTSIDE;
|
return IS_OUTSIDE;
|
||||||
@ -258,24 +255,35 @@ INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
|||||||
for (auto & face : faces)
|
for (auto & face : faces)
|
||||||
{
|
{
|
||||||
Vec<3> v0 = p - points[face.pnums[0]];
|
Vec<3> v0 = p - points[face.pnums[0]];
|
||||||
|
if (printing)
|
||||||
|
{
|
||||||
|
*testout << "face: ";
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
*testout << points[face.pnums[j]] << " ";
|
||||||
|
*testout << endl;
|
||||||
|
}
|
||||||
double lamn = face.nn * v0;
|
double lamn = face.nn * v0;
|
||||||
|
|
||||||
if (fabs(lamn) < eps) // point is in plance of face
|
if (fabs(lamn) < eps) // point is in plane of face
|
||||||
{
|
{
|
||||||
double lam1 = face.w1 * v0;
|
double lam1 = face.w1 * v0;
|
||||||
double lam2 = face.w2 * v0;
|
double lam2 = face.w2 * v0;
|
||||||
double lam3 = 1-lam1-lam2;
|
double lam3 = 1-lam1-lam2;
|
||||||
|
if (printing)
|
||||||
|
*testout << "lam = " << lam1 << " " << lam2 << " " << lam3 << endl;
|
||||||
if (lam1 >= -eps_base1 && lam2 >= -eps_base1 && lam3 >= -eps_base1)
|
if (lam1 >= -eps_base1 && lam2 >= -eps_base1 && lam3 >= -eps_base1)
|
||||||
{ // point is close to trianlge, perturbe by alpha*v
|
{ // point is close to trianlge, perturbe by alpha*v
|
||||||
double dlamn = face.nn*v;
|
double dlamn = face.nn*v;
|
||||||
double dlam1 = face.w1 * v;
|
|
||||||
double dlam2 = face.w2 * v;
|
|
||||||
double dlam3 = 1-dlam1-dlam2;
|
|
||||||
|
|
||||||
if (fabs(dlamn) < 1e-8) // vec also in plane
|
if (fabs(dlamn) < 1e-8) // vec also in plane
|
||||||
{
|
{
|
||||||
|
if (printing)
|
||||||
|
*testout << "tang in plane" << endl;
|
||||||
|
double dlam1 = face.w1 * v;
|
||||||
|
double dlam2 = face.w2 * v;
|
||||||
|
double dlam3 = 1-dlam1-dlam2;
|
||||||
|
if (printing)
|
||||||
|
*testout << "dlam = " << dlam1 << " " << dlam2 << " " << dlam3 << endl;
|
||||||
bool in1 = lam1 > eps_base1 || dlam1 > -eps_base1;
|
bool in1 = lam1 > eps_base1 || dlam1 > -eps_base1;
|
||||||
bool in2 = lam2 > eps_base1 || dlam2 > -eps_base1;
|
bool in2 = lam2 > eps_base1 || dlam2 > -eps_base1;
|
||||||
bool in3 = lam3 > eps_base1 || dlam3 > -eps_base1;
|
bool in3 = lam3 > eps_base1 || dlam3 > -eps_base1;
|
||||||
@ -284,24 +292,41 @@ INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
|||||||
}
|
}
|
||||||
else // vec out of plane
|
else // vec out of plane
|
||||||
{
|
{
|
||||||
|
if (printing)
|
||||||
|
*testout << "out of plane";
|
||||||
double dlamn = -(face.n * v) / (face.n * n);
|
double dlamn = -(face.n * v) / (face.n * n);
|
||||||
|
if (printing)
|
||||||
|
*testout << "dlamn = " << dlamn << endl;
|
||||||
if (dlamn < 0) continue; // ray goes not in direction of face
|
if (dlamn < 0) continue; // ray goes not in direction of face
|
||||||
|
|
||||||
Vec<3> drs = v0 + lamn * n;
|
Vec<3> drs = v + dlamn * n;
|
||||||
|
if (printing)
|
||||||
|
{
|
||||||
|
*testout << "drs = " << drs << endl;
|
||||||
|
*testout << "face.w1 = " << face.w1 << endl;
|
||||||
|
*testout << "face.w2 = " << face.w2 << endl;
|
||||||
|
}
|
||||||
|
|
||||||
double dlam1 = dlamn * face.w1 * v;
|
double dlam1 = face.w1 * drs;
|
||||||
double dlam2 = dlamn * face.w2 * v;
|
double dlam2 = face.w2 * drs;
|
||||||
double dlam3 = 1-dlam1-dlam2;
|
double dlam3 = -dlam1-dlam2;
|
||||||
|
|
||||||
|
if (printing)
|
||||||
|
*testout << "dlam = " << dlam1 << " " << dlam2 << " " << dlam3 << endl;
|
||||||
|
|
||||||
bool in1 = lam1 > eps_base1 || dlam1 > -eps_base1;
|
bool in1 = lam1 > eps_base1 || dlam1 > -eps_base1;
|
||||||
bool in2 = lam2 > eps_base1 || dlam2 > -eps_base1;
|
bool in2 = lam2 > eps_base1 || dlam2 > -eps_base1;
|
||||||
bool in3 = lam3 > eps_base1 || dlam3 > -eps_base1;
|
bool in3 = lam3 > eps_base1 || dlam3 > -eps_base1;
|
||||||
|
|
||||||
if (in1 && in2 && in3)
|
if (in1 && in2 && in3)
|
||||||
|
{
|
||||||
|
if (printing)
|
||||||
|
*testout << "hit" << endl;
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double lamn = -(face.n * v0) / (face.n * n);
|
double lamn = -(face.n * v0) / (face.n * n);
|
||||||
@ -314,14 +339,43 @@ INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
|||||||
double lam2 = face.w2 * rs;
|
double lam2 = face.w2 * rs;
|
||||||
double lam3 = 1-lam1-lam2;
|
double lam3 = 1-lam1-lam2;
|
||||||
if (lam1 >= 0 && lam2 >= 0 && lam3 >= 0)
|
if (lam1 >= 0 && lam2 >= 0 && lam3 >= 0)
|
||||||
|
{
|
||||||
|
if (printing)
|
||||||
|
*testout << "hit" << endl;
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (cnt % 2) ? IS_INSIDE : IS_OUTSIDE;
|
return (cnt % 2) ? IS_INSIDE : IS_OUTSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p,
|
||||||
|
const Vec<3> & v,
|
||||||
|
double eps) const
|
||||||
|
{
|
||||||
|
return VecInSolidOld (p, v, eps);
|
||||||
|
/*
|
||||||
|
auto oldval = VecInSolidOld (p, v, eps);
|
||||||
|
auto newval = VecInSolidNew (p, v, eps);
|
||||||
|
if (oldval != newval)
|
||||||
|
{
|
||||||
|
*testout << "different decision: oldval = " << oldval
|
||||||
|
<< " newval = " << newval << endl;
|
||||||
|
*testout << "p = " << p << ", v = " << v << endl;
|
||||||
|
VecInSolidNew (p, v, eps, true);
|
||||||
|
*testout << "Poly:" << endl;
|
||||||
|
for (auto & face : faces)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
*testout << points[face.pnums[j]] << " ";
|
||||||
|
*testout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newval;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,10 +54,18 @@ namespace netgen
|
|||||||
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const;
|
||||||
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
|
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
|
||||||
double eps) const;
|
double eps) const;
|
||||||
|
virtual INSOLID_TYPE VecInSolidNew (const Point<3> & p,
|
||||||
|
const Vec<3> & v,
|
||||||
|
double eps, bool printing = false) const;
|
||||||
|
virtual INSOLID_TYPE VecInSolidOld (const Point<3> & p,
|
||||||
|
const Vec<3> & v,
|
||||||
|
double eps) const;
|
||||||
virtual INSOLID_TYPE VecInSolid (const Point<3> & p,
|
virtual INSOLID_TYPE VecInSolid (const Point<3> & p,
|
||||||
const Vec<3> & v,
|
const Vec<3> & v,
|
||||||
double eps) const;
|
double eps) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// checks if lim s->0 lim t->0 p + t(v1 + s v2) in solid
|
// checks if lim s->0 lim t->0 p + t(v1 + s v2) in solid
|
||||||
virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,
|
virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,
|
||||||
const Vec<3> & v1,
|
const Vec<3> & v1,
|
||||||
|
Loading…
Reference in New Issue
Block a user