- 积分
- 3116
- 明经币
- 个
- 注册时间
- 2004-6-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2006-11-4 20:19:00
|
显示全部楼层
<RE class=prog_in_0>Acad::ErrorStatus</PRE><RE class=prog_in_0>AsdkPoly::intersectWith(</PRE><RE class=prog_in_0> const AcDbEntity* ent,</PRE><RE class=prog_in_0> AcDb::Intersect intType,</PRE><RE class=prog_in_0> const AcGePlane& projPlane,</PRE><RE class=prog_in_0> AcGePoint3dArray& points,</PRE><RE class=prog_in_0> int /*thisGsMarker*/,</PRE><RE class=prog_in_0> int /*otherGsMarker*/) const</PRE><RE class=prog_in_0>{</PRE><RE class=prog_in_0> assertReadEnabled();</PRE><RE class=prog_in_0> Acad::ErrorStatus es = Acad::eOk;</PRE><RE class=prog_in_0> if (ent == NULL)</PRE><RE class=prog_in_0> return Acad::eNullEntityPointer;</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> // The idea is to intersect each side of the polygon</PRE><RE class=prog_in_0> // with the given entity and return all the points.</PRE><RE class=prog_in_0> // </PRE><RE class=prog_in_0> // For non-R12-entities, with intersection methods defined,</PRE><RE class=prog_in_0> // we call that method for each of the sides of the polygon. </PRE><RE class=prog_in_0> // For R12-entities, we use the locally defined intersectors,</PRE><RE class=prog_in_0> // since their protocols are not implemented.</PRE><RE class=prog_in_0> //</PRE><RE class=prog_in_0> if (ent->isKindOf(AcDbLine::desc())) {</PRE><RE class=prog_in_0> if ((es = intLine(this, AcDbLine::cast(ent),</PRE><RE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> } else if (ent->isKindOf(AcDbArc::desc())) {</PRE><RE class=prog_in_0> if ((es = intArc(this, AcDbArc::cast(ent), intType,</PRE><RE class=prog_in_0> &projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> } else if (ent->isKindOf(AcDbCircle::desc())) {</PRE><RE class=prog_in_0> if ((es = intCircle(this, AcDbCircle::cast(ent),</PRE><RE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> } else if (ent->isKindOf(AcDb2dPolyline::desc())) {</PRE><RE class=prog_in_0> if ((es = intPline(this, AcDb2dPolyline::cast(ent),</PRE><RE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> } else if (ent->isKindOf(AcDb3dPolyline::desc())) {</PRE><RE class=prog_in_0> if ((es = intPline(this, AcDb3dPolyline::cast(ent),</PRE><RE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> } else {</PRE><RE class=prog_in_0> AcGePoint3dArray vertexArray;</PRE><RE class=prog_in_0> if ((es = getVertices3d(vertexArray))</PRE><RE class=prog_in_0> != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> if (intType == AcDb::kExtendArg</PRE><RE class=prog_in_0> || intType == AcDb::kExtendBoth)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> intType = AcDb::kExtendThis;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> AcDbLine *pAcadLine;</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> for (int i = 0; i < vertexArray.length() - 1; i++) {</PRE><RE class=prog_in_0> pAcadLine = new AcDbLine();</PRE><RE class=prog_in_0> pAcadLine->setStartPoint(vertexArray);</PRE><RE class=prog_in_0> pAcadLine->setEndPoint(vertexArray[i + 1]);</PRE><RE class=prog_in_0> pAcadLine->setNormal(normal());</PRE><RE class=prog_in_0> if ((es = ent->intersectWith(pAcadLine, intType,</PRE><RE class=prog_in_0> projPlane, points)) != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> delete pAcadLine;</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> delete pAcadLine;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> // All the points that we selected in this process are on</PRE><RE class=prog_in_0> // the other curve; we are dealing with apparent</PRE><RE class=prog_in_0> // intersection. If the other curve is 3D or is not</PRE><RE class=prog_in_0> // on the same plane as poly, the points are not on</PRE><RE class=prog_in_0> // poly.</PRE><RE class=prog_in_0> // </PRE><RE class=prog_in_0> // In this case, we need to do some more work. Project the</PRE><RE class=prog_in_0> // points back onto the plane. They should lie on</PRE><RE class=prog_in_0> // the projected poly. Find points on real poly</PRE><RE class=prog_in_0> // corresponding to the projected points.</PRE><RE class=prog_in_0> //</PRE><RE class=prog_in_0> AcGePoint3d projPt, planePt;</PRE><RE class=prog_in_0> AcGePoint3dArray pts;</PRE><RE class=prog_in_0> AcGeLine3d line;</PRE><RE class=prog_in_0> </PRE><RE class=prog_in_0> AcGePlane polyPlane;</PRE><RE class=prog_in_0> AcDb::Planarity plnrty;</PRE><RE class=prog_in_0> getPlane(polyPlane,plnrty);</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> for (i = 0; i < points.length(); i++) {</PRE><RE class=prog_in_0> // Define a line starting from the projPt and</PRE><RE class=prog_in_0> // along the normal. Intersect the polygon with</PRE><RE class=prog_in_0> // that line. Find all the points and pick the</PRE><RE class=prog_in_0> // one closest to the given point.</PRE><RE class=prog_in_0> //</PRE><RE class=prog_in_0> projPt = points.orthoProject(projPlane);</PRE><RE class=prog_in_0> line.set(projPt, projPlane.normal());</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> if ((es = intLine(this, line, pts))</PRE><RE class=prog_in_0> != Acad::eOk)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> planePt = projPt.project(polyPlane,</PRE><RE class=prog_in_0> projPlane.normal());</PRE><RE class=prog_in_0> points = pts[0];</PRE><RE class=prog_in_0> double length = (planePt - pts[0]).length();</PRE><RE class=prog_in_0> double length2;</PRE><RE class=prog_in_0></PRE><RE class=prog_in_0> for (int j = 1; j < pts.length(); j++) {</PRE><RE class=prog_in_0> if ((length2 = (planePt - pts[j]).length())</PRE><RE class=prog_in_0> < length)</PRE><RE class=prog_in_0> {</PRE><RE class=prog_in_0> points = pts[j];</PRE><RE class=prog_in_0> length = length2;</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> }</PRE><RE class=prog_in_0> return es;</PRE><RE class=prog_in_end_0>}</PRE><RE class=prog_in_end_0> </PRE> |
|