## 03-ObjectArx-创建圆 原

c
caiweicaiwei

1.由于两点创建圆用到根据两点计算圆心和半径，新建筛选器CwCalculation，并新建类CwCalculation

CwCalculation.h

``````#pragma once

class CwCalculation
{
public:
CwCalculation(void);
public:
~CwCalculation(void);
public:
static AcGePoint2d MiddlePoint(AcGePoint2d pt1,AcGePoint2d pt2);
static AcGePoint3d MiddlePoint(AcGePoint3d pt1,AcGePoint3d pt2);
};
``````

CwCalculation.cpp

``````#include "StdAfx.h"
#include "CwCalculation.h"

CwCalculation::CwCalculation(void)
{
}

CwCalculation::~CwCalculation(void)
{
}

AcGePoint2d CwCalculation::MiddlePoint(AcGePoint2d pt1,AcGePoint2d pt2)
{
AcGePoint2d pt;
pt[X]=(pt1[X]+pt2[X])/2;
pt[Y]=(pt1[Y]+pt2[Y])/2;
return pt;
}

AcGePoint3d CwCalculation::MiddlePoint(AcGePoint3d pt1,AcGePoint3d pt2)
{
AcGePoint3d pt;
pt[X]=(pt1[X]+pt2[X])/2;
pt[Y]=(pt1[Y]+pt2[Y])/2;
pt[Z]=(pt1[Z]+pt2[Z])/2;
return pt;
}
``````

2.在CwEntity类中添加创建圆

CwEntity.h

``````static AcDbObjectId CreateCircle(AcGePoint3d ptCenter,AcGeVector3d vec,double radius);
static AcDbObjectId CreateCircle(AcGePoint3d ptCenter,double radius);
static AcDbObjectId CreateCircle(AcGePoint2d pt1,AcGePoint2d pt2);``````

CwEntity.cpp

``````AcDbObjectId CwEntity::CreateCircle(AcGePoint3d ptCenter,AcGeVector3d vec,double radius)
{
AcDbCircle *pCircle =new AcDbCircle(ptCenter,vec,radius);
//将实体添加到图形数据库
AcDbObjectId circleId;
circleId = CwDatabase::PostToModelSpace(pCircle);
return circleId;
}

AcDbObjectId CwEntity::CreateCircle(AcGePoint3d ptCenter,double radius)
{
AcGeVector3d vec(0,0,1);
}

AcDbObjectId CwEntity::CreateCircle(AcGePoint2d pt1,AcGePoint2d pt2)
{
//计算圆心和半径
AcGePoint2d pt=CwCalculation::MiddlePoint(pt1,pt2);
AcGePoint3d ptCenter(pt[X],pt[Y],0);
}``````

3.在Commands中添加实现

``void CreateCircle();``

``````void CreateCircle()
{
//圆心，半径画圆
AcGePoint3d ptCenter(100,100,0);
CwEntity::CreateCircle(ptCenter,20);
//两点画圆
AcGePoint2d pt1(70, 100);
AcGePoint2d pt2(130, 100);
CwEntity::CreateCircle(pt1,pt2);
}``````

4.实现效果

c

### 评论(0)

Win10下vs2015 ObjectARX向导创建项目失败解决方法

wxplol
03/31
0
0
ObjectARX解压包内各文件代表什么？

2016/11/16
183
0

wwl33695
2014/04/17
0
0
ObjectARX_将实体添加到图形数据库的模型空间相关函数

（1）getBlockTable 是 AcDbDatabase 类的一个成员函数，用于获得指向图形数据库的块表的指针。 getBlockTable 函数的定义形式为： 该函数的返回值 Acad::ErrorStatus 是 ObjectARX 中定义的...

2016/10/17
487
0

zhao_anan
2019/01/27
0
0

2019/08/14
9
0

javail

15
0
DevOps与NoOps现状分析

tidings_

21
0
OSChina 周六乱弹 —— 代码创造人工生命

Osc乱弹歌单（2020）请戳（这里） 【今日歌曲】 @小小编辑推荐：《inner universe》 - ORIGA 《inner universe》 - ORIGA 手机党少年们想听歌，请使劲儿戳（这里） 当机器人具有意识的时候，...

20
1

1、IIS7远程桌面 管理中文最新版是一款专业的远程桌面管理工具，更新了原09网络远程桌面管理，较之以前的版本，操作更加便捷，能够同时远程多台服务器，多台服务器间自由切换，完全无压力。I...

22
0