好了,我找到解决这个问题的方法了。
看起来有点笨拙。有人有更简单的方法吗?
- AcDbPolyline * AcGeCurveToAcDbCurve(const AcGeCompositeCurve3d * pGe)
- {
- AcGePoint3d startPnt,endPnt;
- if( pGe->hasEndPoint(endPnt) == Adesk ::kFalse ||
- pGe->hasStartPoint(startPnt) == Adesk::kFalse)
- {
- return NULL;
- }
- //get the plane of Curve3d
- AcGePlane plane;
- AcGeLine3d line;
- AcGePoint3d p1,p2,p3;
- if(pGe->isPlanar(plane))
- {
- if(pGe->isLinear(line)) //Oh,it's a little tricky!
- {
- line.getPerpPlane(startPnt,plane);
- plane.get(p1,p2,p3);
- plane.set(p2,p3-p2);
- }
- plane.get(p1,p2,p3);
- }
- else
- {
- return NULL;
- }
- //Creat a polyline
- AcDbPolyline *pPoly = new AcDbPolyline();
- AcGeVoidPointerArray curveList;
- pGe->getCurveList(curveList);
- AcGeCurve3d *pCurve = NULL;
- AcGeCircArc3d *pArc = NULL;
-
- int i;
- double b;
- AcGePoint2d pt;
- for(i = 0;i hasStartPoint(startPnt);
- pt = startPnt.convert2d(plane);
- if (pCurve->isKindOf(AcGe::kCircArc3d))
- {
- pArc = (AcGeCircArc3d *)(pCurve);
- b = tan(0.25*(pArc->endAng() - pArc->startAng()));
- if (pArc->normal().z addVertexAt(i,pt,-b);
- }
- else
- {
- pPoly->addVertexAt(i,pt,b);
- }
- }
- else
- {
- pPoly->addVertexAt(i,pt);
- }
- }
- if(!pGe->isClosed())
- {
- pt = endPnt.convert2d(plane);
- pPoly->addVertexAt(i,pt);
- }
- else
- {
- pPoly->setClosed(Adesk::kTrue);
- }
- //the most important step;
- AcGeMatrix3d xform;
- AcGeVector3d XAxis = p1-p2;
- AcGeVector3d YAxis = p3-p2;
- AcGeVector3d ZAxis = XAxis.crossProduct(YAxis);
- xform.setCoordSystem(p2,XAxis,YAxis,ZAxis);
- pPoly->transformBy(xform);
- return pPoly;
- }
|