[求助]我写的计算面积的函数总觉得有点不对劲,高手看看?
float Draw2dPLArea(){
AcGePoint2dArray points;
AcGePoint3d myptCurrent;
ads_point pt,ptStart;
AcGePoint3d pthigh;
int i=0;
double area=0;
ads_point ptPrevious, ptCurrent; // 前一个参考点,当前拾取的点
int index = 2; // 当前输入点的次数
AcDbObjectId polyId; // 多段线的ID
int ptnum=0;
int rc; // 返回值
ACHAR kword; // 关键字
acedInitGet(RSG_NONULL,_T("C"));
//提示用户选择想要勾画的工程面积点
if (acedGetPoint(NULL, _T("\n输入第一点:"),ptStart) != RTNORM)
return 0;
acdbPointSet(ptStart, ptPrevious);
while (acedGetPoint(ptPrevious,_T("\n输入下一点:"), ptCurrent) ==RTNORM)
{
if (index==2)
{
// 创建多段线
AcGePoint2d ptGe1, ptGe2; // 两个节点
ptGe1 = ptPrevious;
ptGe1 = ptPrevious;
ptGe2 = ptCurrent;
ptGe2 = ptCurrent;
points.insertAt(0,ptGe1);
points.insertAt(1,ptGe2);
/*pPoly->addVertexAt(0, ptGe1);
pPoly->addVertexAt(1, ptGe2);*/
}
else if (index>2)
{
// 修改多段线,添加最后一个顶点
AcGePoint2d ptGe; // 增加的节点
ptGe = ptCurrent;
ptGe = ptCurrent;
/*pPoly->addVertexAt(index - 1, ptGe);*/
points.insertAt(index-1,ptGe);
}
index++;
acdbPointSet(ptCurrent, ptPrevious);
}
//add points into AcDbLine
int vexnum=points.length();
AcDbPolyline *pPoly=new AcDbPolyline(vexnum);
for(i=0;iaddVertexAt(i,points.at(i));
}
pPoly->getArea(area);
pPoly->close();
return area;
}
高手帮看看行么?总觉得有些地方不妥。小妹谢谢了!
AcDbPolyline *pPoly=new AcDbPolyline();
for(i=0;iaddVertexAt(i,points.at(i));
}
其他的对么?总感觉不是很完整?另外正么将起点设为高亮,方便用户捕捉?谢谢?
请各位各抒己见! 返回结果是对的。
最好设置多线为闭合。
acedGetPoint在这情况不太合用,可以尝试用AcEdJig类。
AcEdJig没用过,您能简单介绍下么?我查帮助怎么是用于拖拽的呢?
页:
[1]