|
[code]
bool IsInside(const AcGePoint3d &pt, AcDbPolyline* pPoly)
{
bool isinside = false;
//CPolylineUtil::clearDbPts(pPoly); //去除相邻重复点
AcGePoint3dArray points,inPts;
AcGePoint3d pt3d;
AcDbExtents ext;
int num = pPoly->numVerts();
for (int i = 0; i < num; i++)
{
pPoly->getPointAt(i, pt3d);
points.append(pt3d);
}
ErrorStatus es= pPoly->getGeomExtents(ext);
double xDis = ext.maxPoint().x - ext.minPoint().x;
AcGeVector3d vec(xDis, 0, 0);
AcDbLine* pLine = new AcDbLine(pt, pt + vec);
if (pLine->intersectWith(pPoly,AcDb::kExtendArg,AcGePlane::kXYPlane,inPts)==Acad ::eOk)
{
int len = inPts.length();
if (len==0)
{
pLine->close();
return isinside;
}
AcGePoint3d ptFront, ptBack;
for (int j=0;j<inPts.length();j++)
{
pt3d = inPts.at(j);
if (points.contains(pt3d))
{
int index = points.find(pt3d);
ptFront = points.at(index - 1);
ptBack = points.at(index + 1);
AcGeVector3d vecFront(pt3d-ptFront);
AcGeVector3d vecBack(ptBack-pt3d);
while (vecFront.isParallelTo(vec))
{
AcGePoint3d ptTemp(ptFront);
ptFront = points.at(points.find(ptTemp) - 1);
vecFront=(AcGeVector3d(ptTemp - ptFront));
}
while (vecBack.isParallelTo(vec))
{
AcGePoint3d pttemp(ptBack);
ptBack = points.at(points.find(pttemp) + 1);
vecBack = (AcGeVector3d(ptBack - pttemp));
}
if (vec.crossProduct(vecFront).isCodirectionalTo(vec.crossProduct(vecBack)))
{
len += 2;
}
else
{
len += 1;
}
}
}
if (len%2!=0)
{
isinside = true;
}
}
pLine->close();
return isinside;
}[/code] |
|