- UID
- 765036
- 积分
- 479
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2016-11-25
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- /*在网上看到:Lee Mac LISP_Programming写的相关LISP程序,较好,学习其算法思路。
- 但在多次均匀旋转角度在[0,180]范围内查询最小面积时,也许会正好错过实体上的轮廓特殊点线,导致计算结果总与实际轮廓线,总差那么一丁点。
- 我的程序,加进了对轮廓线上的特殊点角度的计算处理,解决了上述问题!!!
- */
- void draw_Min_EntSet_Box()
- {
- AcDbObjectIdArray objIdArr;
- ads_name ss={0L,0L};
- //选择实体
- if(acedSSGet(NULL,NULL,NULL,NULL,ss)!=RTNORM)
- {
- acutPrintf("\n用户取消!");
- return;
- }
- long len=0;
- acedSSLength(ss,&len);
- for(int i=0;i<len;i++)
- {
- ads_name ent={0L,0L};
- acedSSName(ss,i,ent);
- AcDbObjectId objId;
- acdbGetObjectId(objId,ent);
- objIdArr.append(objId);
- }
- acedSSFree(ss);
- //获得实体组端点线组成的特殊角度:从小到大
- CArray<double,double> angArr;
- getEntsPtAngle(objIdArr,angArr);
- //
- //初始状态:获得实体组的范围
- AcDbExtents ext0;
- Get_AllEnt_Extents(objIdArr,ext0);
- AcGePoint3d centerPt=ext0.minPoint()+(ext0.maxPoint()-ext0.minPoint())/2.0;
- //最小值
- double minAngle=0.0;
- AcDbExtents minExt=ext0;
- //
- int n=2000;
- //acutPrintf("\n进入角度循环!");
- for(int j=1;j<n;j++)
- {
- double curAngle=j*PI/n;
- //acutPrintf("\n当前旋转角:%f",curAngle);
- AcDbExtents curExt;
- rotateEntSet(objIdArr,centerPt,curAngle);
- Get_AllEnt_Extents(objIdArr,curExt);
- rotateEntSet(objIdArr,centerPt,-curAngle);
- double curArea,minArea;
- curArea=(curExt.maxPoint()[0]-curExt.minPoint()[0])*(curExt.maxPoint()[1]-curExt.minPoint()[1]);
- minArea=(minExt.maxPoint()[0]-minExt.minPoint()[0])*(minExt.maxPoint()[1]-minExt.minPoint()[1]);
- //acutPrintf("\n当前面积:%f;最小面积:%f",curArea,minArea);
- if(curArea<minArea)
- {
- minExt.set(curExt.minPoint(),curExt.maxPoint());;
- minAngle=curAngle;
- }
- //
- if(j==n-1)
- {
- acutPrintf("\n暴力浏览:%d 次完毕!",n);
- }
- }
- //
- //acutPrintf("\n特殊点的角度数:%d",angArr.GetSize());
- //特殊角度
- for(int k=0;k<angArr.GetSize();k++)
- {
- double curAngle=angArr[k];
- AcDbExtents curExt;
- rotateEntSet(objIdArr,centerPt,-curAngle);
- Get_AllEnt_Extents(objIdArr,curExt);
- rotateEntSet(objIdArr,centerPt,curAngle);
- double curArea,minArea;
- curArea=(curExt.maxPoint()[0]-curExt.minPoint()[0])*(curExt.maxPoint()[1]-curExt.minPoint()[1]);
- minArea=(minExt.maxPoint()[0]-minExt.minPoint()[0])*(minExt.maxPoint()[1]-minExt.minPoint()[1]);
- //acutPrintf("\n当前面积:%f;最小面积:%f",curArea,minArea);
- if(curArea-minArea<0.0)
- {
- minExt.set(curExt.minPoint(),curExt.maxPoint());;
- minAngle=-curAngle;
- acutPrintf("\n特殊点角度的最小值交换:成功!");
- }
- else
- {
- ;//acutPrintf("\n特殊点的最小值:不交换!");
- }
- if(k==angArr.GetSize()-1)
- {
- acutPrintf("\n特殊点角度浏览:%d 次完毕!",angArr.GetSize());
- }
- }
- //特殊角度
- //
- //建立矩形
- //AcDbExtents minExt;
- AcDbPolyline* pPLine=new AcDbPolyline();
- pPLine->addVertexAt(0,AcGePoint2d(minExt.minPoint()[0],minExt.minPoint()[1]));
- pPLine->addVertexAt(1,AcGePoint2d(minExt.maxPoint()[0],minExt.minPoint()[1]));
- pPLine->addVertexAt(2,AcGePoint2d(minExt.maxPoint()[0],minExt.maxPoint()[1]));
- pPLine->addVertexAt(3,AcGePoint2d(minExt.minPoint()[0],minExt.maxPoint()[1]));
- pPLine->setClosed(Adesk::kTrue);
- //加入
- AcDbBlockTable* pBT=NULL;
- AcDbBlockTableRecord* pBTRec=NULL;
- acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBT,AcDb::kForRead);
- pBT->getAt(ACDB_MODEL_SPACE,pBTRec,AcDb::kForWrite);
- pBT->close();
- pBTRec->appendAcDbEntity(pPLine);
- //转换
- //acutPrintf("\n旋转角:%f",minAngle*180/PI);
- AcGeMatrix3d xform;
- xform.setToRotation(-minAngle,AcGeVector3d(0,0,1),centerPt);
- pPLine->transformBy(xform);
- //
- pPLine->close();
- pBTRec->close();
- //
- }
|
|