天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 57|回复: 0

OBJECTARX编程--圆

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
以下分别通过“圆心,半径”,“直径和两端点”和“三点法”创建圆
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)//画圆

 

 

 

 

OBJECTARX编程--圆
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 13:41 , Processed in 0.157824 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表