明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1634|回复: 1

[ARX]随点画了N边形,请问怎么得到这个N边形的面积

[复制链接]
发表于 2005-9-27 15:49:00 | 显示全部楼层 |阅读模式
随点画了个N边形,请问怎么得到这个N边形的面积,好象可以通过这种方法得到:
AcDbPolyline * pPline ;
double area=0;
pPline->getArea(area);
acutPrintf("\n面积为 %.3f\n",area);
可是我不知道如何添加?(加了几次了都取不到面积 很郁闷 )
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

ads_point pt1[512];
AcGePoint3d pt[512];
int NodeNumCount;
void area()
{
int i=0;
acedGetPoint(NULL,"\n请选择起始点:",asDblArray(pt[0]));

do {
acedGetPoint(asDblArray(pt),"\n拾取下一点:",asDblArray(pt[i+1]));
AcDbLine *pLine=new AcDbLine(pt,pt[i+1]);
AcDbBlockTable *pBlkTable2;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlkTable2, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;

pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
pBlkTable2->close();

AcDbObjectId lineId=AcDbObjectId::kNull;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
pBlockTableRecord->close();
pLine->close();
changepoint(pt1[i+1],pt[i+1]);//转换点的类型
changepoint(pt1[0],pt[0]);//转换点的类型
i++;
NodeNumCount=i;//取得边数
}
while((Equal_Points (pt1, pt1[0]))==0);//起始点=终点时结束循环
}

int Equal_Points (const ads_point p1, const ads_point p2) //判断两点是否为同一点
{
// 指定误差范围
const ads_real Equality_Margin = (ads_real)0.0001;
int c ;
for (c = X ; c <= Z ; c++)
{
if (fabs(p1[c] - p2[c]) > Equality_Margin)
{return (0) ;}
}
{
AcDbLine *pLine=new AcDbLine(pt[0],pt[NodeNumCount]);
AcDbBlockTable *pBlkTable2;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlkTable2, AcDb::kForRead);

AcDbBlockTableRecord *pBlockTableRecord;

pBlkTable2->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
pBlkTable2->close();

AcDbObjectId lineId=AcDbObjectId::kNull;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
pBlockTableRecord->close();
pLine->close();
return (1) ;
}
}

void changepoint(ads_point& ads_pt,AcGePoint3d acge_pt) //AcGePoint3d转换成ads_point类型
{
double x=acge_pt[0];
double y=acge_pt[1];
double z=acge_pt[2];
ads_pt[X]=x;
ads_pt[Y]=y;
ads_pt[Z]=z;
}
发表于 2012-8-28 20:55:52 | 显示全部楼层
把多边形变成N个三角形,然后用海伦公式计算就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 08:48 , Processed in 0.156390 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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