|
AcDbPolyline* ConvertEllipseToPline(AcDbEllipse* pEllipse)
{
if(!pEllipse)
return NULL;
double dParam;
double dLength;
double dStep;
BOOL bClosed=TRUE;
AcGePoint3d pt3d;
std::vector<AcGePoint3d> arPt3;
pEllipse->getEndParam(dParam);
pEllipse->getDistAtParam(dParam,dLength);
const unsigned dSegments=100;//divide ellipse into 100 segments
dStep=(dLength/dSegments)>1?(dLength/dSegments):1;
if(!pEllipse->isClosed())
bClosed=FALSE;
for(double dDist=0.0;dDist<dLength;dDist=dDist+dStep)
{
pEllipse->getPointAtDist(dDist,pt3d);
arPt3.push_back(pt3d);
}
pEllipse->getEndPoint(pt3d);
if(pt3d.distanceTo(arPt3.back())>0.0001)
arPt3.push_back(pt3d);
AcDbPolyline* pPline=new AcDbPolyline();
for(size_t i=0;i<arPt3.size();i++)
pPline->addVertexAt(i,AcGePoint2d(arPt3[i].x,arPt3[i].y));
pPline->setClosed(bClosed);
pPline->setPropertiesFrom(pEllipse);
return pPline;
}
double dParamStart;
es = pEllipse->getStartParam(dParamStart);
dStep = (dParam - dParamStart) / dSegments;
for (double par = dParamStart; par<= dParam; par+=dStep)
{
es = pEllipse->getPointAtParam(par, pt3d);
arPt3.push_back(pt3d);
} |
|