天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 24|回复: 0

按顺序等距排列平行直线

[复制链接]
  • TA的每日心情
    开心
    3 天前
  • 签到天数: 82 天

    [LV.6]常住居民II

    1591

    主题

    204

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 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. }
    复制代码

     

     

     

     

    按顺序等距排列平行直线
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-19 05:20 , Processed in 0.059962 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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