[每日一码] 显示封闭多边形的形心
void cmdDispProperty(){
ArxDbgUiPrEntity prEnt(采用T("请选择由 Pline组成的封闭多边形"), NULL);
prEnt.addAllowedClass(AcDbPolyline::desc());
if (prEnt.go() != ArxDbgUiPrBase::kOk)
{
return;
}
AcDbEntity* pEnt1 = NULL;
acdbOpenObject(pEnt1,prEnt.objectId(),AcDb::kForRead);
//获得封闭形顶点
AcDbPolyline *Polygon = NULL ;
Polygon = AcDbPolyline::cast(pEnt1);
ASSERT( Polygon != NULL );
if (Polygon == NULL)
{
AfxMessageBox(采用T("线型不为多义线"));
pEnt1->close();
return;
}
if( !Polygon->isClosed() )
{
Polygon->close();
AfxMessageBox(采用T("外轮廓不封闭"));
return;
}
AcGePoint3d *pPtArray;//记录外轮廓上的点
int VertNum = (int)Polygon->numVerts() ;
pPtArray = new AcGePoint3d;
int i;
for( i = 0; i < VertNum; i ++ )
{
AcGePoint3d Temp;
Polygon->getPointAt(i,Temp);
pPtArray<i> = Temp;
}
pEnt1->close();
AcGePoint3d centroid;
GetCentroidPt(pPtArray, VertNum, centroid);
TCHAR Text;
采用stprintf(Text, 采用T("%.3f"), centroid.y);
DelGroupEnt(采用T("neuotrol"));
DrawElevLine2(centroid,Text,采用T("Neuotrol"));
}
页:
[1]