该函数有两种形式:intersectWith() virtual Acad::ErrorStatus intersectWith( const AcDbEntity* ent, AcDb::Intersect intType, AcGePoint3dArray& points, int thisGsMarker = 0, int otherGsMarker = 0) const; virtual Acad::ErrorStatus intersectWith( const AcDbEntity* ent, AcDb::Intersect intType, const AcGePlane& projPlane, AcGePoint3dArray& points, int thisGsMarker = 0, int otherGsMarker = 0) const; 函数测试的第一种形式,用于两个实体的简单交集。第二种形式计算投影平面上的交点。但是,这两个函数都返回实体本身的交点。若要实现自定义行为,请重写相应的函数。intersectWith()subIntersectWith() 使用 intersectWith() 函数的投影平面形式
自定义类覆盖函数的两种形式。AsdkPolysubIntersectWith() Acad::ErrorStatus AsdkPoly::subIntersectWith( const AcDbEntity* ent, AcDb::Intersect intType, AcGePoint3dArray& points, int /*thisGsMarker*/, int /*otherGsMarker*/) const { assertReadEnabled(); Acad::ErrorStatus es = Acad::eOk; if (ent == NULL) return Acad::eNullEntityPointer; // The idea is to intersect each side of the polygon // with the given entity and return all the points. // // For non-R12-entities, with // intersection methods defined, we call that method for // each of the sides of the polygon. For R12-entities, // we use the locally defined intersectors, since their // protocols are not implemented. // if (ent->isKindOf(AcDbLine::desc())) { if ((es = intLine(this, AcDbLine::cast(ent), intType, NULL, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDbArc::desc())) { if ((es = intArc(this, AcDbArc::cast(ent), intType, NULL, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDbCircle::desc())) { if ((es = intCircle(this, AcDbCircle::cast(ent), intType, NULL, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDb2dPolyline::desc())) { if ((es = intPline(this, AcDb2dPolyline::cast(ent), intType, NULL, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDb3dPolyline::desc())) { if ((es = intPline(this, AcDb3dPolyline::cast(ent), intType, NULL, points)) != Acad::eOk) { return es; } } else { AcGePoint3dArray vertexArray; if ((es = getVertices3d(vertexArray)) != Acad::eOk) { return es; } if (intType == AcDb::kExtendArg || intType == AcDb::kExtendBoth) { intType = AcDb::kExtendThis; } AcDbLine *pAcadLine; for (int i = 0; i < vertexArray.length() - 1; i++) { pAcadLine = new AcDbLine(); pAcadLine->setStartPoint(vertexArray[i]); pAcadLine->setEndPoint(vertexArray[i + 1]); pAcadLine->setNormal(normal()); if ((es = ent->intersectWith(pAcadLine, intType, points)) != Acad::eOk) { delete pAcadLine; return es; } delete pAcadLine; } } return es; } Acad::ErrorStatus AsdkPoly::subIntersectWith( const AcDbEntity* ent, AcDb::Intersect intType, const AcGePlane& projPlane, AcGePoint3dArray& points, int /*thisGsMarker*/, int /*otherGsMarker*/) const { assertReadEnabled(); Acad::ErrorStatus es = Acad::eOk; if (ent == NULL) return Acad::eNullEntityPointer; // The idea is to intersect each side of the polygon // with the given entity and return all the points. // // For non-R12-entities, with // intersection methods defined, we call that method for // each of the sides of the polygon. For R12-entities, // we use the locally defined intersectors, since their // protocols are not implemented. // if (ent->isKindOf(AcDbLine::desc())) { if ((es = intLine(this, AcDbLine::cast(ent), intType, &projPlane, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDbArc::desc())) { if ((es = intArc(this, AcDbArc::cast(ent), intType, &projPlane, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDbCircle::desc())) { if ((es = intCircle(this, AcDbCircle::cast(ent), intType, &projPlane, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDb2dPolyline::desc())) { if ((es = intPline(this, AcDb2dPolyline::cast(ent), intType, &projPlane, points)) != Acad::eOk) { return es; } } else if (ent->isKindOf(AcDb3dPolyline::desc())) { if ((es = intPline(this, AcDb3dPolyline::cast(ent), intType, &projPlane, points)) != Acad::eOk) { return es; } } else { AcGePoint3dArray vertexArray; if ((es = getVertices3d(vertexArray)) != Acad::eOk) { return es; } if (intType == AcDb::kExtendArg || intType == AcDb::kExtendBoth) { intType = AcDb::kExtendThis; } AcDbLine *pAcadLine; int i; for (i = 0; i < vertexArray.length() - 1; i++) { pAcadLine = new AcDbLine(); pAcadLine->setStartPoint(vertexArray[i]); pAcadLine->setEndPoint(vertexArray[i + 1]); pAcadLine->setNormal(normal()); if ((es = ent->intersectWith(pAcadLine, intType, projPlane, points)) != Acad::eOk) { delete pAcadLine; return es; } delete pAcadLine; } // All the points that we selected in this process are on // the other curve; we are dealing with apparent // intersection. If the other curve is 3D or is not // on the same plane as poly, the points are not on // poly. // // In this case, we need to do some more work. Project the // points back onto the plane. They should lie on // the projected poly. Find points on real poly // corresponding to the projected points. AcGePoint3d projPt, planePt; AcGePoint3dArray pts; AcGeLine3d line; AcGePlane polyPlane; AcDb::Planarity plnrty; getPlane(polyPlane,plnrty); for (i = 0; i < points.length(); i++) { // Define a line starting from the projPt and // along the normal. Intersect the polygon with // that line. Find all the points and pick the // one closest to the given point. // projPt = points[i].orthoProject(projPlane); line.set(projPt, projPlane.normal()); if ((es = intLine(this, line, pts)) != Acad::eOk) { return es; } planePt = projPt.project(polyPlane, projPlane.normal()); points[i] = pts[0]; double length = (planePt - pts[0]).length(); double length2; for (int j = 1; j < pts.length(); j++) { if ((length2 = (planePt - pts[j]).length()) < length) { points[i] = pts[j]; length = length2; } } } } return es; } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:18
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.