当前位置: 首页 > news >正文

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

//from:起点,to:终点(这两点要相邻)
//paramDis:沿着多段线画多长
//pl:多段线
//pPoly:新的多段线
static void DrawByLen(const bool& gotoNext ,const AcGePoint2d& from,const AcGePoint2d& to,const double& paramDis,const AcDbPolyline* pl,AcDbPolyline* pPoly,int& polyIndex)
{
if(paramDis <= 0)
{
return;
}
int len = pl->numVerts();

AcGeCircArc2d arc2d;
AcGeLineSeg2d line2d;


AcGePoint2d ptS;
AcGePoint2d ptE;
bool isFind = false;
int plIndex = 0;
AcGeCurve2d* pCurve = NULL;

for(int i = 0;i < len;i++)
{
AcDbPolyline::SegType st = pl->segType(i);

if(st == AcDbPolyline::SegType::kArc)
{
pl->getArcSegAt(i,arc2d);
pCurve = &arc2d;
}
else if(st == AcDbPolyline::SegType::kLine)
{
pl->getLineSegAt(i,line2d);
pCurve = &line2d;
}


if(!pCurve->hasStartPoint(ptS) || !pCurve->hasEndPoint(ptE))
{
continue;
}

if(ptS == from && ptE == to || ptS == to && ptE == from)
{
plIndex = i;
isFind = true;
break;
}
}


double sumDis = 0.0;
if(isFind)
{
DrawIt(gotoNext,pl,paramDis,from,polyIndex,plIndex,sumDis,pPoly);
}
else
{
acutPrintf(_T("\nnot found"));
}
}


//summary
//指定一个起点和一条多段线,沿着多段线画出指定距离,递归执行,每次往后(前)移动一个点,直到画完指定的距离,
//pl:多段线
//paramDis:画多长
//ptStart:起始点
//polyIndex:添加到第几个了
//plIndex,遍历到多段线第几条线
//isSToE,遍历的顺序1:从前向后  0:从后向前
//sumDis,目前画的总长度
//pPoly:画出来的多段线
static void DrawIt(const bool& gotoNext,const AcDbPolyline* pl,const double& paramDis,const AcGePoint2d& ptStart,int& polyIndex,int& plIndex,double& sumDis,AcDbPolyline* pPoly)
{

AcDbPolyline::SegType st = pl->segType(plIndex);
AcGePoint2d ptS;
AcGePoint2d ptE;
double leftDis = 0.0;
double curveDis = 0.0;
double bulge = 0.0;
AcGeCurve2d* pCurve = NULL;
AcGeCircArc2d arc2d;
AcGeLineSeg2d line2d;
int len = pl->numVerts();


if(polyIndex == 2*(len - 2))
{
acutPrintf(_T("\nend poly is %d"),polyIndex);
return;
}


if(st == AcDbPolyline::SegType::kArc)
{
pl->getArcSegAt(plIndex,arc2d);
pCurve = &arc2d;!!!注意:指针的生命周期一定要大于等于指向的变量的生命周期,否则变量release掉指针就空了,再次使用指针程序直接崩溃!!
}
else if(st == AcDbPolyline::SegType::kLine)
{
pl->getLineSegAt(plIndex,line2d);
pCurve = &line2d;
}
if(!pCurve->hasStartPoint(ptS) || !pCurve->hasEndPoint(ptE))
{
return;
}
curveDis = pCurve->length(pCurve->paramOf(ptS),pCurve->paramOf(ptE));
leftDis = paramDis - sumDis;


pl->getBulgeAt(plIndex,bulge);


if(curveDis > leftDis)
{
double paramEnding = 0.0;

if(gotoNext)
{
AcGePoint2d ptEnding;
AcGePoint2d ptS;
pCurve->hasStartPoint(ptS);
GetPtAtDistOnCurve(pCurve,ptS,leftDis,ptEnding,Adesk::kTrue);


bulge = tan(atan(bulge) * leftDis/curveDis);


pPoly->addVertexAt(polyIndex,ptS,bulge);
polyIndex ++;
pPoly->addVertexAt(polyIndex,ptEnding);
}
else
{
AcGePoint2d ptEnding;
AcGePoint2d ptE;
pCurve->hasEndPoint(ptE);
GetPtAtDistOnCurve(pCurve,ptE,leftDis,ptEnding,Adesk::kFalse);


bulge = tan(atan(bulge) * leftDis/curveDis);


pPoly->addVertexAt(polyIndex,ptE,-bulge);
polyIndex ++;
pPoly->addVertexAt(polyIndex,ptEnding);
}
return;
}
else
{
if(gotoNext)
{
pPoly->addVertexAt(polyIndex,ptS,bulge);
polyIndex ++;
pPoly->addVertexAt(polyIndex,ptE);
polyIndex ++;
//acutPrintf(_T("\nplIndex is %d,poly is %d。is goto next,bulge is %.2f"),plIndex,polyIndex,bulge);
}
else
{
pPoly->addVertexAt(polyIndex,ptE,-bulge);
polyIndex ++;
pPoly->addVertexAt(polyIndex,ptS);
polyIndex ++;

}
/*acutPrintf(_T("\nptS[X] :%.2f,ptS[Y]:%.2f,ptE[X]:%.2f,ptE[Y]:%.2f"),ptS[X],ptS[Y],ptE[X],ptE[Y]);*/
sumDis += curveDis;

}


if(gotoNext)
{
plIndex = plIndex < len - 1  ? ++plIndex : 0;
}
else
{
plIndex = plIndex > 0 ? --plIndex : len - 1;
}


DrawIt(gotoNext,pl,paramDis,ptStart,polyIndex,plIndex,sumDis,pPoly);


}

反回曲线上一定距离的点(默认从起点开始计算)
pCurve:曲线指针,dist:距离,point:要返回的点
Adesk::Boolean isGotoNext  true:沿着正向寻找,false:沿着反方向寻找
static void GetPtAtDistOnCurve(const AcGeCurve2d* pCurve,const AcGePoint2d& ptInput,double dist,AcGePoint2d& point,Adesk::Boolean isGotoNext)
{
if(pCurve == NULL)
{
return;
}
AcGePoint2d ptS;
ptS = ptInput;
double pa = 0.0;
double datumParam = 0.0;
//Adesk::Boolean posParamDir = Adesk::kTrue;

datumParam = pCurve->paramOf(ptS);
pa = pCurve->paramAtLength(datumParam,dist,isGotoNext);
point = pCurve->evalPoint(pa);
}


相关文章:

  • WinDBG 技巧: 显示GetLastError() 错误码 (!gle命令)
  • C# 窗体间传值总结
  • 诺基亚5800XM 承认质量缺陷
  • ASP.NET Web Application 中使用 Unity 依赖注入容器
  • ARX 多段线的合并
  • 参加ESB沙龙
  • 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
  • Unix哲学基础
  • C# EXCEL 导入导出类(OLEDB的方式)
  • 相声:我要谈恋爱
  • C# 操作EXCEL样式 示例 --生成EXCEL审计表
  • C# 操作EXCEL
  • 新浪评出2008年度IT博客
  • c# 隐藏已打开的窗口,打开登陆窗口
  • 十个常用的S60手机软件
  • exports和module.exports
  • HTTP 简介
  • JavaScript DOM 10 - 滚动
  • k8s如何管理Pod
  • Median of Two Sorted Arrays
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • nginx 配置多 域名 + 多 https
  • VuePress 静态网站生成
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 记一次用 NodeJs 实现模拟登录的思路
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 前言-如何学习区块链
  • 深度解析利用ES6进行Promise封装总结
  • 数组大概知多少
  • 算法---两个栈实现一个队列
  • 新手搭建网站的主要流程
  • 学习JavaScript数据结构与算法 — 树
  • Prometheus VS InfluxDB
  • 关于Android全面屏虚拟导航栏的适配总结
  • #define与typedef区别
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • (SpringBoot)第七章:SpringBoot日志文件
  • .cfg\.dat\.mak(持续补充)
  • @DateTimeFormat 和 @JsonFormat 注解详解
  • [22]. 括号生成
  • [BUUCTF 2018]Online Tool
  • [C++][基础]1_变量、常量和基本类型
  • [CentOs7]搭建ftp服务器(2)——添加用户
  • [delphi]保证程序只运行一个实例
  • [emacs] CUA的矩形块操作很给力啊
  • [IE编程] 如何获得IE版本号
  • [leetcode]Symmetric Tree
  • [MQ]常用的mq产品图形管理web界面或客户端
  • [Oh My C++ Diary]#ifndef / #define / #endif 使用详解
  • [one_demo_10]递归解决汉诺塔问题
  • [POJ2411]Mondriaan's Dream
  • [Redis]Redis的数据类型
  • [Script]采用Python创建当前日期文件夹
  • [Web开发] 如何改变IE滚动条的颜色