创建圆

 

 

ObjectArx中创建圆的函数

AcDbCircle(const AcGePoint3d& cntr, const AcGeVector3d& nrm, double radius);

cntr:圆心

nrm:圆所在平面,用法向量(0,0,1)表示XY平面

radius:半径

 

如何创建圆

1 AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter, AcGeVector3d vec, DOUBLE radius)
2 {
3     AcDbObjectId oId;
4     AcDbCircle* pCircle = new AcDbCircle(ptCenter,vec,radius);   //创建圆
5 
6     oId   = CCreateEnt::PostToModelSpace(pCircle);    //提交到模型空间
7     return oId;
8 
9 }

PostToModelSpace函数在上一节实现 

 

创建XY平面上的圆

1 AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter, DOUBLE radius)
2 {
3     AcDbObjectId oId;
4     AcGeVector3d vec(0,0,1);    //代表XY平面的法向量
5     AcDbCircle* pCircle = new AcDbCircle(ptCenter,vec,radius);
6     oId = CCreateEnt::PostToModelSpace(pCircle);
7     return oId;    
8 }

 

两点创建圆

1 AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2)
2 {
3     AcGePoint2d pt = CCalculation::MiddlePoint(pt1,pt2);    //获取中点
4     AcGePoint3d ptCenter(pt.x,pt.y,0);
5     DOUBLE radius = pt1.distanceTo(pt2)/2;    //获取半径
6     return CCreateEnt::CreateCircle(ptCenter,radius);
7 }

MiddlePoint函数求两个点的中点,这里就不贴出具体实现方法了

 

三点创建圆

AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2, AcGePoint2d pt3)
{
    AcGeCircArc2d geArc(pt1,pt2,pt3);    //创建AcGeCircArc对象
    AcGePoint3d ptCenter(geArc.center().x,geArc.center().y,0);    //获取圆心
    return CCreateEnt::CreateCircle(ptCenter,geArc.radius());
}

AcGeCircArc2d表示一个几何类的圆弧对象,该对象仅用于计算,不能在图形窗口中显示

 

测试圆创建功能

 1 public:
 2 
 3     // ----- CADShellCreateEntsUnmanaged._AddCircle command
 4     static void CADShellCreateEntsUnmanaged_AddCircle(void)
 5     {
 6         AcGePoint3d ptCenter(100,100,0);
 7         CCreateEnt::CreateCircle(ptCenter,20);
 8 
 9         AcGePoint2d pt1(70,100);
10         AcGePoint2d pt2(130,100);
11         CCreateEnt::CreateCircle(pt1,pt2);
12 
13         pt1.set(60,100);
14         pt2.set(140,100);
15         AcGePoint2d pt3(100,60);
16         CCreateEnt::CreateCircle(pt1,pt2,pt3);
17 
18     }

 

 

 

 

 

 

 

 

 

 

 

posted on 2013-05-30 18:48  CQU  阅读(388)  评论(0编辑  收藏  举报

导航