找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 147|回复: 0

按顺序等距排列平行直线

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-4 18:42:08 | 显示全部楼层 |阅读模式
  1. static void zffObjectARX采用MyCommand17(void)
  2. {
  3. ads采用name ss;
  4. AcDbVoidPtrArray ents;
  5. if (acedSSGet(NULL,NULL,NULL,NULL,ss)!=RTNORM)
  6. {
  7. acedAlert(采用T("选择实体失败!"));
  8. return;
  9. }
  10. AcGePoint3dArray pts;
  11. long num;
  12. acedSSLength(ss,&num);
  13. if (num<3)
  14. {
  15. acedAlert(采用T("无需均分!"));
  16. return;
  17. }
  18. for (int i=0;i<num;i++)
  19. {
  20. AcDbObjectId entId;
  21. AcDbEntity* pEnt=NULL;
  22. ads采用name name;
  23. AcGePoint3d pt;
  24. acedSSName(ss,i,name);
  25. acdbGetObjectId(entId,name);
  26. if (acdbOpenObject(pEnt,entId,AcDb::kForWrite)!=Acad::eOk)
  27. {
  28. acedAlert(采用T("部分实体打开失败,无法均分!"));
  29. pEnt->close();
  30. return;
  31. }
  32. if (pEnt->isKindOf(AcDbLine::desc()))
  33. {
  34. AcDbLine* pLine=AcDbLine::cast(pEnt);
  35. pLine->getClosestPointTo(AcGePoint3d::kOrigin,pt,Adesk::kTrue);
  36. pts.append(pt);
  37. ents.append(static采用cast<void*>(pLine));
  38. }
  39. else
  40. {
  41. pEnt->close();
  42. }
  43. }
  44. acedSSFree(ss);
  45. AcGePoint3d pt1,pt2;
  46. double dist=0,dist1;
  47. long len=pts.length();
  48. for (int i=0;i<len;i++)
  49. {
  50. for (int j=i+1;j<len;j++)
  51. {
  52. dist1=pts[i].distanceTo(pts[j]);
  53. if (dist1>dist)
  54. {
  55. dist=dist1;
  56. pt1=pts[i];
  57. pt2=pts[j];
  58. }
  59. }
  60. }
  61. pts.remove(pt1);
  62. pts.remove(pt2);
  63. int m,n=0;
  64. for (int j=0;j<pts.length();)
  65. {
  66. dist=pt1.distanceTo(pt2);
  67. for (int i=0;i<pts.length();i++)
  68. {
  69. dist1=pts[i].distanceTo(pt1);
  70. if (dist1<dist)
  71. {
  72. dist=dist1;
  73. m=i;
  74. }
  75. }
  76. AcGeVector3d vec=pt1-pts[m]-(pt1-pt2)*(n+1)/(len-1);
  77. AcGeMatrix3d max;
  78. max.setToTranslation(vec);
  79. for (int i=0;i<ents.length();i++)
  80. {
  81. AcDbLine* pLine=static采用cast<AcDbLine*>(ents[i]);
  82. AcGePoint3d ptclose;
  83. pLine->getClosestPointTo(pts[m],ptclose,Adesk::kTrue);
  84. if (pts[m].distanceTo(ptclose)<0.001)
  85. {
  86. pLine->transformBy(max);
  87. }
  88. }
  89. pts.remove(pts[m]);
  90. n++;
  91. }
  92. for (int i=0;i<ents.length();i++)
  93. {
  94. AcDbLine* pLine1=static采用cast<AcDbLine*>(ents[i]);
  95. pLine1->close();
  96. }
  97. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-4 13:13 , Processed in 0.094929 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表