highflyingbird 发表于 2010-7-21 10:51:18

如何将AcGeCompositeCurve3d转换为AcDbPolyline?

这是我的代码。
AcDbPolyline * AcGeCurveToAcDbCurve(const AcGeCompositeCurve3d * pGe)
{
        AcGePoint3d startPnt,endPnt;
        if(pGe->hasEndPoint(endPnt) == Adesk ::kFalse || pGe->hasStartPoint(startPnt) == Adesk::kFalse)
                return NULL;
        AcGePlane plane;
             pGe->isPlanar(plane);
       
        AcGePoint2d pt;
        AcDbPolyline *pPoly = new AcDbPolyline();
        AcGeVoidPointerArray curveList;
        pGe->getCurveList(curveList);
        AcGeCurve3d *pCurve        = NULL;
        AcGeLine3d *pLine        = NULL;
             AcGeCircArc3d *arc        = NULL;
       
        int i;
        for(i = 0;i hasStartPoint(startPnt);
                pt = startPnt.convert2d(plane);
                if (pCurve->isKindOf(AcGe::kLineSeg3d))
                {
                        pPoly->addVertexAt(i,pt);
                }
                else if (pCurve->isKindOf(AcGe::kCircArc3d))
                {
                        arc = (AcGeCircArc3d *)(pCurve);
                        double b = tan(0.25*(arc->endAng() - arc->startAng()))*(arc->normal().z);
                        pPoly->addVertexAt(i,pt,b);
                }
        }
        pPoly->addVertexAt(i,endPnt.convert2d(plane),0,0,0);
        return pPoly;
}
但是当AcGeCompositeCurve3d的法线不是(0 0 1)时,它工作不正确。怎么了?
**** Hidden Message *****

highflyingbird 发表于 2010-7-21 10:56:05


这是可以将AcDbPolyline转换为AcGeCompositeCurve3d的代码。它确实有效。
// POLYLINE
AcGeCompositeCurve3d * AcDbCurveToAcGeCurve(const AcDbPolyline * pPoly)
{
        AcGeLineSeg3d *pLine = NULL;
        AcGeCircArc3d *pArc = NULL;
        AcGeVoidPointerArray GeCurves;
        for( int i = 0; i numVerts(); i++ )
        {
                if( pPoly->segType(i) == AcDbPolyline::kLine )
                {
                        pLine = new AcGeLineSeg3d;
                        pPoly->getLineSegAt(i, *pLine);
                        GeCurves.append(pLine);
                }
                else if( pPoly->segType(i) == AcDbPolyline::kArc )
                {
                        pArc = new AcGeCircArc3d;
                        pPoly->getArcSegAt(i, *pArc);
                        GeCurves.append(pArc);
                }
        }
        returnnew AcGeCompositeCurve3d(GeCurves);
}

highflyingbird 发表于 2010-7-22 10:27:36

好了,我找到解决这个问题的方法了。
看起来有点笨拙。有人有更简单的方法吗?
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;
}
页: [1]
查看完整版本: 如何将AcGeCompositeCurve3d转换为AcDbPolyline?