计算多段线中圆弧的圆心 Calculating the Center of an Arc in a Polyline using ObjectARX

作者: admin 分类: C++,CAD,ObjectARX 发布时间: 2022-04-06 20:47

https://adndevblog.typepad.com/autocad/2012/12/calculating-the-center-of-an-arc-in-a-polyline-using-objectarx.html

12/10/2012

Calculating the Center of an Arc in a Polyline using ObjectARX

by Fenton Webb

The easiest way to do this is to construct an AcGeCircArc2d or AcGeCircArc3d

object and then use its center() method to get the point you want.

The following function finds any arc segments in a lightweight polyline and

identifies the center by dropping a point entity (AcDbPoint) in the calculated

location.

#include <dbobjptr.h>

void show_centers()

{     

  // UI for selecting an entity  

  ads_name en;  

  ads_point pt;  

  int rc = acedEntSel(L"Select LW polyline: ", en, pt);  

  if (rc != RTNORM)

  {  

    acutPrintf(L"Nothing selected.\n", rc);  

    return;   

  }      

 

  // convert ads_name to object id 

  AcDbObjectId eId;    

  Acad::ErrorStatus es = acdbGetObjectId(eId, en);  

  // open object 

  AcDbObjectPointer<AcDbPolyline> pPolyline(eId, AcDb::kForRead);

  if(pPolyline.openStatus() != Acad::eOk)  

  {  

    acutPrintf(L"You did not select a LW polyline.\n");    

    return;   

  }   

 

  // get the number of segments  

  int segments = pPolyline->numVerts() – 1;  

  for(int i = 0; i < segments; i++)

  {   

    if(pPolyline->segType(i) != AcDbPolyline::kArc)

      continue;   

 

    // get arc segment on polyline   

    AcGeCircArc2d geArc;   

    pPolyline->getArcSegAt(i, geArc);   

    // get center   

    AcGePoint2d center = geArc.center();   

    // create a point entity   

    AcDbObjectPointer<AcDbPoint> pPoint;

    AcDbPoint *pointPtr = new AcDbPoint(AcGePoint3d(center[0],

  center[1], 0.0));

    pPoint.acquire(pointPtr);     

 

    // add the point entity to the block table record   

    // containing the selected polyline   

    AcDbBlockTableRecordPointer curSpace(pPolyline->blockId(),

      AcDb::kForWrite);

    if (curSpace.openStatus() == Acad::eOk)

      curSpace->appendAcDbEntity(pPoint);   

 

    acutPrintf(L"\n – center: [%f, %f]", center[0], center[1]);

  }  

}

 

Posted at 03:14 PM in 2010, 2011, 2012, 2013, AutoCAD, Fenton Webb, ObjectARX | Permalink

发表评论

您的电子邮箱地址不会被公开。

标签云