|
以下分别通过“圆心,半径”,“直径和两端点”和“三点法”创建圆
CreateEnt.h:
static AcDbObjectId CreateCircle(AcGePoint3d ptCenter,AcGeVector3d vec, double radius);//画圆
static AcDbObjectId CreateCircle(AcGePoint3d ptCenter, double radius);
static AcDbObjectId CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2);//两点画圆
static AcDbObjectId CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2,AcGePoint2d pt3);//三点画圆
CreateEnt.cpp:
//圆心,半径
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter,AcGeVector3d vec, double radius)
{
AcDbCircle *pCircle = new AcDbCircle(ptCenter, vec, radius);
// 将实体添加到图形数据库
AcDbObjectId circleId;
circleId = CCreateEnt::PostToModelSpace(pCircle);
return circleId;
}
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter, double radius)
{
AcGeVector3d vec(0, 0, 1);
return CCreateEnt::CreateCircle(ptCenter, vec, radius);
}
//用两点画圆
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1,AcGePoint2d pt2){
//计算圆心和半径
AcGePoint2d pt=CCalculation::MiddlePoint(pt1,pt2);
AcGePoint3d ptCenter(pt[X],pt[Y],0);//圆心
double radius=pt1.distanceTo(pt2)/2;
//创建圆
return CCreateEnt::CreateCircle(ptCenter,radius)
}
//三点画圆
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1,AcGePoint2d pt2, AcGePoint2d pt3){
//使用几何类
AcGeCircArc2d geArc(pt1,pt2,pt3);
AcGePoint3d ptCenter(geArc.center().x,geArc.center().y,0);
return CCreateEnt::CreateCircle(ptCenter,geArc.radius());
}
//获得两点连线的中点,也就是圆心
AcGePoint2d CCalculation::MiddlePoint(AcGePoint2d pt1, AcGePoint2d pt2)
{
AcGePoint2d pt;
pt[X] = (pt1[X] + pt2[X]) / 2;
pt[Y] = (pt1[Y] + pt2[Y]) / 2;
return pt;
}
#include "gearc3d.h"
AcGePoint3d CCalculation::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;
}
/acrxEntryPoint.cpp:
static void MLMyGroupAddCircle()
{
// “圆心、半径”法创建一个圆
AcGePoint3d ptCenter(100, 100, 0);
CCreateEnt::CreateCircle(ptCenter, 20);
// 两点法创建一个圆
AcGePoint2d pt1(70, 100);
AcGePoint2d pt2(130, 100);
CCreateEnt::CreateCircle(pt1, pt2);
// 三点法创建一个圆
pt1.set(60, 100);
pt2.set(140, 100);
AcGePoint2d pt3(100, 60);
CCreateEnt::CreateCircle(pt1, pt2, pt3);
}
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProjectMLApp, MLMyGroup, AddCircle, CreateCircler, ACRX_CMD_MODAL, NULL)//画圆 |
|