找回密码
 立即注册

QQ登录

只需一步,快速开始

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

ARX 沿着多段线绘制一定距离,递归执行

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:42:10 | 显示全部楼层 |阅读模式
  1. //from:起点,to:终点(这两点要相邻)
  2. //paramDis:沿着多段线画多长
  3. //pl:多段线
  4. //pPoly:新的多段线
  5. static void DrawByLen(const bool& gotoNext ,const AcGePoint2d& from,const AcGePoint2d& to,const double& paramDis,const AcDbPolyline* pl,AcDbPolyline* pPoly,int& polyIndex)
  6. {
  7. if(paramDis <= 0)
  8. {
  9. return;
  10. }
  11. int len = pl->numVerts();
  12. AcGeCircArc2d arc2d;
  13. AcGeLineSeg2d line2d;
  14. AcGePoint2d ptS;
  15. AcGePoint2d ptE;
  16. bool isFind = false;
  17. int plIndex = 0;
  18. AcGeCurve2d* pCurve = NULL;
  19. for(int i = 0;i < len;i++)
  20. {
  21. AcDbPolyline::SegType st = pl->segType(i);
  22. if(st == AcDbPolyline::SegType::kArc)
  23. {
  24. pl->getArcSegAt(i,arc2d);
  25. pCurve = &arc2d;
  26. }
  27. else if(st == AcDbPolyline::SegType::kLine)
  28. {
  29. pl->getLineSegAt(i,line2d);
  30. pCurve = &line2d;
  31. }
  32. if(!pCurve->hasStartPoint(ptS) || !pCurve->hasEndPoint(ptE))
  33. {
  34. continue;
  35. }
  36. if(ptS == from && ptE == to || ptS == to && ptE == from)
  37. {
  38. plIndex = i;
  39. isFind = true;
  40. break;
  41. }
  42. }
  43. double sumDis = 0.0;
  44. if(isFind)
  45. {
  46. DrawIt(gotoNext,pl,paramDis,from,polyIndex,plIndex,sumDis,pPoly);
  47. }
  48. else
  49. {
  50. acutPrintf(采用T("\nnot found"));
  51. }
  52. }
  53. //summary
  54. //指定一个起点和一条多段线,沿着多段线画出指定距离,递归执行,每次往后(前)移动一个点,直到画完指定的距离,
  55. //pl:多段线
  56. //paramDis:画多长
  57. //ptStart:起始点
  58. //polyIndex:添加到第几个了
  59. //plIndex,遍历到多段线第几条线
  60. //isSToE,遍历的顺序1:从前向后  0:从后向前
  61. //sumDis,目前画的总长度
  62. //pPoly:画出来的多段线
  63. static void DrawIt(const bool& gotoNext,const AcDbPolyline* pl,const double& paramDis,const AcGePoint2d& ptStart,int& polyIndex,int& plIndex,double& sumDis,AcDbPolyline* pPoly)
  64. {
  65. AcDbPolyline::SegType st = pl->segType(plIndex);
  66. AcGePoint2d ptS;
  67. AcGePoint2d ptE;
  68. double leftDis = 0.0;
  69. double curveDis = 0.0;
  70. double bulge = 0.0;
  71. AcGeCurve2d* pCurve = NULL;
  72. AcGeCircArc2d arc2d;
  73. AcGeLineSeg2d line2d;
  74. int len = pl->numVerts();
  75. if(polyIndex == 2*(len - 2))
  76. {
  77. acutPrintf(采用T("\nend poly is %d"),polyIndex);
  78. return;
  79. }
  80. if(st == AcDbPolyline::SegType::kArc)
  81. {
  82. pl->getArcSegAt(plIndex,arc2d);
  83. pCurve = &arc2d;!!!注意:指针的生命周期一定要大于等于指向的变量的生命周期,否则变量release掉指针就空了,再次使用指针程序直接崩溃!!
  84. }
  85. else if(st == AcDbPolyline::SegType::kLine)
  86. {
  87. pl->getLineSegAt(plIndex,line2d);
  88. pCurve = &line2d;
  89. }
  90. if(!pCurve->hasStartPoint(ptS) || !pCurve->hasEndPoint(ptE))
  91. {
  92. return;
  93. }
  94. curveDis = pCurve->length(pCurve->paramOf(ptS),pCurve->paramOf(ptE));
  95. leftDis = paramDis - sumDis;
  96. pl->getBulgeAt(plIndex,bulge);
  97. if(curveDis > leftDis)
  98. {
  99. double paramEnding = 0.0;
  100. if(gotoNext)
  101. {
  102. AcGePoint2d ptEnding;
  103. AcGePoint2d ptS;
  104. pCurve->hasStartPoint(ptS);
  105. GetPtAtDistOnCurve(pCurve,ptS,leftDis,ptEnding,Adesk::kTrue);
  106. bulge = tan(atan(bulge) * leftDis/curveDis);
  107. pPoly->addVertexAt(polyIndex,ptS,bulge);
  108. polyIndex ++;
  109. pPoly->addVertexAt(polyIndex,ptEnding);
  110. }
  111. else
  112. {
  113. AcGePoint2d ptEnding;
  114. AcGePoint2d ptE;
  115. pCurve->hasEndPoint(ptE);
  116. GetPtAtDistOnCurve(pCurve,ptE,leftDis,ptEnding,Adesk::kFalse);
  117. bulge = tan(atan(bulge) * leftDis/curveDis);
  118. pPoly->addVertexAt(polyIndex,ptE,-bulge);
  119. polyIndex ++;
  120. pPoly->addVertexAt(polyIndex,ptEnding);
  121. }
  122. return;
  123. }
  124. else
  125. {
  126. if(gotoNext)
  127. {
  128. pPoly->addVertexAt(polyIndex,ptS,bulge);
  129. polyIndex ++;
  130. pPoly->addVertexAt(polyIndex,ptE);
  131. polyIndex ++;
  132. //acutPrintf(采用T("\nplIndex is %d,poly is %d。is goto next,bulge is %.2f"),plIndex,polyIndex,bulge);
  133. }
  134. else
  135. {
  136. pPoly->addVertexAt(polyIndex,ptE,-bulge);
  137. polyIndex ++;
  138. pPoly->addVertexAt(polyIndex,ptS);
  139. polyIndex ++;
  140. }
  141. /*acutPrintf(采用T("\nptS[X] :%.2f,ptS[Y]:%.2f,ptE[X]:%.2f,ptE[Y]:%.2f"),ptS[X],ptS[Y],ptE[X],ptE[Y]);*/
  142. sumDis += curveDis;
  143. }
  144. if(gotoNext)
  145. {
  146. plIndex = plIndex < len - 1  ? ++plIndex : 0;
  147. }
  148. else
  149. {
  150. plIndex = plIndex > 0 ? --plIndex : len - 1;
  151. }
  152. DrawIt(gotoNext,pl,paramDis,ptStart,polyIndex,plIndex,sumDis,pPoly);
  153. }
  154. 反回曲线上一定距离的点(默认从起点开始计算)
  155. pCurve:曲线指针,dist:距离,point:要返回的点
  156. Adesk::Boolean isGotoNext  true:沿着正向寻找,false:沿着反方向寻找
  157. static void GetPtAtDistOnCurve(const AcGeCurve2d* pCurve,const AcGePoint2d& ptInput,double dist,AcGePoint2d& point,Adesk::Boolean isGotoNext)
  158. {
  159. if(pCurve == NULL)
  160. {
  161. return;
  162. }
  163. AcGePoint2d ptS;
  164. ptS = ptInput;
  165. double pa = 0.0;
  166. double datumParam = 0.0;
  167. //Adesk::Boolean posParamDir = Adesk::kTrue;
  168. datumParam = pCurve->paramOf(ptS);
  169. pa = pCurve->paramAtLength(datumParam,dist,isGotoNext);
  170. point = pCurve->evalPoint(pa);
  171. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-1-4 12:50 , Processed in 0.104406 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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