admin 发表于 2024-3-14 20:44:05

[每日一码] ARX射线法判断点是否在多边形内

//*************************************************************
//利用射线法判断一点是否在窗口内,如果在内部返回1,否则返回0
//其中输入参数pt是被判断点,boundarypt是辅助边界点,用于作射线用
//*********************1-14-2001 by Meishuli

int inwindow(ads采用point pt,ads采用point boundarypt,ads采用name windowent)
{
ads采用name ent0;
int rt;

AcDbEntity *pent,*pwindowent;
    AcDbObjectId pentId,pwindowentId;
AcGePoint3dArray points;
int CrossPtsNum;
AcGePoint3d Pts,BoundaryPts;
AcDbObjectId auxlineId;
    Acad::ErrorStatus es;

Pts.set(pt,pt,0);
BoundaryPts.set(boundarypt,boundarypt,0);

auxlineId=createLine(Pts,BoundaryPts);
acdbEntLast(ent0);

pwindowent=selectEntity(pwindowentId,windowent,AcDb::kForRead);
pent=selectEntity(pentId,ent0,AcDb::kForRead);

es=pwindowent->intersectWith(pent,AcDb::kOnBothOperands,points,0,0);
    if (es == Acad::eOk) {
      CrossPtsNum=points.length(); //计算交点的数量CrossPtsNum
      points.setLogicalLength(0);
}
else {
      acutPrintf("\nerror!--inwindow()\n");

      pent->close();
    acdbEntDel(ent0);
      pwindowent->close();
    return -1;
}
pent->close();
acdbEntDel(ent0);

pwindowent->close();
if(CrossPtsNum % 2 == 0)
   rt = 0;
else rt = 1;
return rt;
}
页: [1]
查看完整版本: [每日一码] ARX射线法判断点是否在多边形内