- 积分
- 683
- 明经币
- 个
- 注册时间
- 2005-8-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
随点画了个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; } |
|