cad新学生 发表于 2009-9-17 09:52:00

[求助]我写的计算面积的函数总觉得有点不对劲,高手看看?

<p>float Draw2dPLArea()<br/>{<br/>&nbsp;AcGePoint2dArray points;<br/>&nbsp;AcGePoint3d myptCurrent;<br/>&nbsp;ads_point pt,ptStart;<br/>&nbsp;AcGePoint3d pthigh;<br/>&nbsp;int i=0;<br/>&nbsp;double area=0;<br/>&nbsp;ads_point ptPrevious, ptCurrent; // 前一个参考点,当前拾取的点<br/>&nbsp;int index = 2; // 当前输入点的次数<br/>&nbsp;AcDbObjectId polyId; // 多段线的ID<br/>&nbsp;int ptnum=0;<br/>&nbsp;<br/>&nbsp;int rc; // 返回值<br/>&nbsp;ACHAR kword; // 关键字<br/>&nbsp;acedInitGet(RSG_NONULL,_T("C"));</p><p>&nbsp;//提示用户选择想要勾画的工程面积点<br/>&nbsp;if (acedGetPoint(NULL, _T("\n输入第一点:"),ptStart) != RTNORM)<br/>&nbsp;&nbsp;return 0;<br/>&nbsp;acdbPointSet(ptStart, ptPrevious);<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;while (acedGetPoint(ptPrevious,_T("\n输入下一点:"), ptCurrent) ==RTNORM)<br/>&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;if (index==2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;// 创建多段线<br/>&nbsp;&nbsp;&nbsp;AcGePoint2d ptGe1, ptGe2; // 两个节点<br/>&nbsp;&nbsp;&nbsp;ptGe1 = ptPrevious;<br/>&nbsp;&nbsp;&nbsp;ptGe1 = ptPrevious;<br/>&nbsp;&nbsp;&nbsp;ptGe2 = ptCurrent;<br/>&nbsp;&nbsp;&nbsp;ptGe2 = ptCurrent;</p><p>&nbsp;&nbsp;&nbsp;points.insertAt(0,ptGe1);<br/>&nbsp;&nbsp;&nbsp;points.insertAt(1,ptGe2);</p><p>&nbsp;&nbsp;&nbsp;/*pPoly-&gt;addVertexAt(0, ptGe1);<br/>&nbsp;&nbsp;&nbsp;pPoly-&gt;addVertexAt(1, ptGe2);*/<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;else if (index&gt;2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;// 修改多段线,添加最后一个顶点<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;AcGePoint2d ptGe; // 增加的节点<br/>&nbsp;&nbsp;&nbsp;ptGe = ptCurrent;<br/>&nbsp;&nbsp;&nbsp;ptGe = ptCurrent;<br/>&nbsp;&nbsp;&nbsp;/*pPoly-&gt;addVertexAt(index - 1, ptGe);*/<br/>&nbsp;&nbsp;&nbsp;points.insertAt(index-1,ptGe);</p><p>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;index++;</p><p>&nbsp;&nbsp;acdbPointSet(ptCurrent, ptPrevious); </p><p><br/>&nbsp;}</p><p><br/>&nbsp;//add points into AcDbLine<br/>&nbsp;int vexnum=points.length();<br/>&nbsp;&nbsp;&nbsp; AcDbPolyline *pPoly=new AcDbPolyline(vexnum);<br/>&nbsp;&nbsp;&nbsp; for(i=0;i&lt;vexnum;i++)<br/>&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pPoly-&gt;addVertexAt(i,points.at(i));<br/>&nbsp;}<br/>&nbsp;</p><p>&nbsp;pPoly-&gt;getArea(area);</p><p>&nbsp;pPoly-&gt;close();</p><p>&nbsp;return area;<br/>}</p><p></p><p>高手帮看看行么?总觉得有些地方不妥。小妹谢谢了!</p><p></p>

梦幻神话 发表于 2009-9-18 09:56:00

AcDbPolyline *pPoly=new AcDbPolyline();<br/>&nbsp;&nbsp;&nbsp; for(i=0;i&lt;vexnum;i++)<br/>&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pPoly-&gt;addVertexAt(i,points.at(i));<br/>&nbsp;}<br/>

cad新学生 发表于 2009-9-18 13:28:00

其他的对么?总感觉不是很完整?另外正么将起点设为高亮,方便用户捕捉?谢谢?
请各位各抒己见!

梦幻神话 发表于 2009-9-18 16:42:00

<p>返回结果是对的。</p><p>最好设置多线为闭合。</p><p>acedGetPoint在这情况不太合用,可以尝试用AcEdJig类。</p><p></p>

cad新学生 发表于 2009-9-19 08:59:00

AcEdJig没用过,您能简单介绍下么?我查帮助怎么是用于拖拽的呢?
页: [1]
查看完整版本: [求助]我写的计算面积的函数总觉得有点不对劲,高手看看?