uusky 发表于 2005-9-27 15:49:00

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

<FONT face=宋体 size=2>随点画了个N边形,请问怎么得到这个N边形的面积,好象可以通过这种方法得到:<BR>AcDbPolyline * pPline ;<BR>double area=0;<BR>pPline-&gt;getArea(area);<BR>acutPrintf("\n面积为 %.3f\n",area);<BR>可是我不知道如何添加?(加了几次了都取不到面积 很郁闷 )<BR>#include <ACED.H><BR>#include <ACEDADS.H><BR>#include <DBENTS.H><BR>#include <DBSYMTB.H><BR>#include <DBGROUP.H><BR>#include <DBAPSERV.H><BR>#include <ACESTEXT.H><BR>#include <MIGRTION.H><BR>#include <GEASSIGN.H><BR>#include <MATH.H><BR>#include <DBPL.H><BR><BR>ads_point pt1;<BR>AcGePoint3d pt;<BR>int NodeNumCount; <BR>void area()<BR>{ <BR>int i=0;<BR>acedGetPoint(NULL,"\n请选择起始点:",asDblArray(pt));<BR><BR>do {<BR>acedGetPoint(asDblArray(pt),"\n拾取下一点:",asDblArray(pt));<BR>AcDbLine *pLine=new AcDbLine(pt,pt);<BR>AcDbBlockTable *pBlkTable2;<BR>acdbHostApplicationServices()-&gt;workingDatabase()<BR>-&gt;getSymbolTable(pBlkTable2, AcDb::kForRead);<BR>AcDbBlockTableRecord *pBlockTableRecord;<BR><BR>pBlkTable2-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>AcDb::kForWrite);<BR>pBlkTable2-&gt;close();<BR><BR>AcDbObjectId lineId=AcDbObjectId::kNull;<BR>pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);<BR>pBlockTableRecord-&gt;close();<BR>pLine-&gt;close();<BR>changepoint(pt1,pt);//转换点的类型<BR>changepoint(pt1,pt);//转换点的类型<BR>i++;<BR>NodeNumCount=i;//取得边数<BR>}<BR>while((Equal_Points (pt1, pt1))==0);//起始点=终点时结束循环<BR>}<BR><BR>int Equal_Points (const ads_point p1, const ads_point p2) //判断两点是否为同一点<BR>{<BR>// 指定误差范围<BR>const ads_real Equality_Margin = (ads_real)0.0001; <BR>int c ;<BR>for (c = X ; c &lt;= Z ; c++) <BR>{<BR>if (fabs(p1 - p2) &gt; Equality_Margin)<BR>{return (0) ;}<BR>}<BR>{<BR>AcDbLine *pLine=new AcDbLine(pt,pt);<BR>AcDbBlockTable *pBlkTable2;<BR>acdbHostApplicationServices()-&gt;workingDatabase()<BR>-&gt;getSymbolTable(pBlkTable2, AcDb::kForRead);<BR><BR>AcDbBlockTableRecord *pBlockTableRecord;<BR><BR>pBlkTable2-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>AcDb::kForWrite);<BR>pBlkTable2-&gt;close();<BR><BR>AcDbObjectId lineId=AcDbObjectId::kNull;<BR>pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);<BR>pBlockTableRecord-&gt;close();<BR>pLine-&gt;close();<BR>return (1) ;<BR>}<BR>}<BR><BR>void changepoint(ads_point&amp; ads_pt,AcGePoint3d acge_pt) //AcGePoint3d转换成ads_point类型<BR>{ <BR>double x=acge_pt; <BR>double y=acge_pt; <BR>double z=acge_pt;<BR>ads_pt=x; <BR>ads_pt=y; <BR>ads_pt=z; <BR>}</FONT>

c735023723 发表于 2012-8-28 20:55:52

把多边形变成N个三角形,然后用海伦公式计算就可以了
页: [1]
查看完整版本: [ARX]随点画了N边形,请问怎么得到这个N边形的面积