objectarx 按比例分割封闭多段线
测试结果:这个是按0.1,0.1,0.1,0.3,0.4的比例划分的。

插件描述:这个插件主要是选择一个多段线poly,设置poly的close属性为true,在poly任意一侧画一条长线line(line画的时候不能与poly相交),找到line的垂直向量p'yXl,这个pyXl是要往与poly能相交的方向。在找到这个line与poly相切的时候。然后取每次平移的步进值bujin,因为这个poly的总面积有大有小,所以我是取总面积totaArea/2000在开方,如果这个bujin<=1,则直接取1,这样对于面积很大的poly也不需要平移很多次。然后就是利用acedTraceBoundary函数来获取平移后的
切线与poly形成的封闭多段线pl,求这个pl的面积是否大与按比例分割后的面积。
需要注意的地方:在使用acedTraceBoundary的时候,必须确认poly和平移的切线都是close掉的,不然无法求出pl。如果没有acedTraceBoundary函数,可以这样:
//ads_point pt = { seedPoint.x,seedPoint.y,seedPoint.z };
//acedCommandS(RTSTR, L"-boundary", RTPOINT, pt, RTSTR, L"", RTNONE);
//acdbEntLast(pent);
////acedRedraw(pent, 3);
//AcDbObjectId eId;
//acdbGetObjectId(eId, pent);
//AcDbPolyline * pEnt = NULL;
//ErrorStatus es = acdbOpenObject(pEnt, eId, AcDb::OpenMode::kForWrite);
来获得封闭的多段线,然后在求面积。
下面给出详细代码:
求pyXl:
AcGeVector3d CAreaFenGe::GetDirection()
{
//l2pt和l1pt是在poly侧边画的线的端点
AcGeVector3d lineDirc = l2Pt - l1Pt;
AcGeVector3d lineDirc2 = l2Pt - l1Pt; AcGePoint3d centerPt((l2Pt.x + l1Pt.x) / , (l2Pt.y + l1Pt.y) / , );
AcGePoint3d ptCloset; poly->getClosestPointTo(centerPt, ptCloset, false); AcDbLine *line1 = AcDbLine::cast(line->clone());
AcDbLine *line2 = AcDbLine::cast(line->clone());
double len = ptCloset.distanceTo(centerPt); AcGeVector3d pyXl1 = lineDirc.rotateBy(- * CMathUtil::PI() / , AcGeVector3d::kZAxis);
AcGeVector3d pyXl2 = lineDirc2.rotateBy(CMathUtil::PI() / , AcGeVector3d::kZAxis); line1->transformBy(AcGeMatrix3d::translation(pyXl1.normal()*len*1.5));
line2->transformBy(AcGeMatrix3d::translation(pyXl2.normal()*len*1.5));
AcGePoint3dArray p3dArr1, p3dArr2; poly->intersectWith(line1, AcDb::Intersect::kExtendArg, p3dArr1, , );
poly->intersectWith(line2, AcDb::Intersect::kExtendArg, p3dArr2, , ); if (p3dArr1.length() > ) {
pyXl = pyXl1;
}
else if(p3dArr2.length()>){
pyXl = pyXl2;
}
else {
pyXl = AcGeVector3d(, -, );//这个可以注释掉
}
delete line1;
line1 = NULL;
delete line2;
line2 = NULL; return pyXl;
}
获得切线:
//得到切线
AcGePoint3d CAreaFenGe::GetQieDian(AcDbLine * &line1)
{ line1 = new AcDbLine(l1Pt, l2Pt); AcGePoint3dArray ptArr; while (ptArr.length() < ) { poly->intersectWith(line1, AcDb::Intersect::kOnBothOperands, ptArr, , ); line1->transformBy(AcGeMatrix3d::translation(pyXl.normal() * )); }
poly->close(); if (ptArr.length() > )
return ptArr[];
else
return AcGePoint3d::kOrigin; }
得到面积:
bool CAreaFenGe::GetPyPolyline(AcGePoint3d seedPoint, double & a)
{ AcDbVoidPtrArray ptrArr;
ErrorStatus es = acedTraceBoundary(seedPoint, false, ptrArr); if (es != Acad::eOk) {
acutPrintf(L"\nboundary=%d", es);
return false;
} AcDbPolyline * pl = NULL;
pl = (AcDbPolyline*)ptrArr[]; pl->setColorIndex(); pl->getArea(a); pl->erase();
pl->close();
pl = NULL;
return true; }
主要步骤:
void CAreaFenGe::Command()
{ ErrorStatus es;
AcDbLine * lQieXian = NULL;
AcGePoint3d ptQieDian = GetQieDian(lQieXian); acutPrintf(L"\nptQieDian=[%.2f,%.2f,%.2f]", ptQieDian.x, ptQieDian.y, ptQieDian.z); ptQieDian=ptQieDian.transformBy(AcGeMatrix3d::translation(pyXl.normal() * ));
acutPrintf(L"\nptQieDian2=[%.2f,%.2f,%.2f]", ptQieDian.x, ptQieDian.y, ptQieDian.z); if (ptQieDian.x == && ptQieDian.y == ) {
return;
}
double bujin = sqrt(totalArea * / ); if (bujin <= ) {
bujin = ;
} AcDbObjectId qxId;
lQieXian->transformBy(AcGeMatrix3d::translation(pyXl.normal() * bujin*)); es = acdbOpenObject(poly, plId, AcDb::kForRead); AcGePoint3dArray ptJdArr; poly->intersectWith(lQieXian, AcDb::Intersect::kOnBothOperands, ptJdArr, , ); if (ptJdArr.length() >= ) { ptQieDian=AcGePoint3d((ptJdArr[].x+ ptJdArr[].x)/, (ptJdArr[].y + ptJdArr[].y) / ,); ptQieDian= ptQieDian.transformBy(AcGeMatrix3d::translation(pyXl.normal() * -bujin*1.5)); }
poly->close(); qxId = CDwgDataBaseUtil::PostToModelSpace(lQieXian); lQieXian->close(); lQieXian = NULL; //AcDbPolyline * ptPy = new AcDbPolyline(); //ptPy->setColorIndex(5); //AcDbObjectId ptId; AcGePoint3dArray ptJdArr2; for (int i = ; i < (int)vecArea.size(); i++)
{ AcGePoint3d ptCopyQd = ptQieDian; double a = 0.0; while (a < vecArea[i]) { bool flag = GetPyPolyline(ptQieDian, a); if (!flag) {
return;
}
es = acdbOpenObject(lQieXian, qxId, AcDb::kForWrite);
lQieXian->transformBy(AcGeMatrix3d::translation(pyXl.normal() * bujin)); ptJdArr2.removeAll(); es = acdbOpenObject(poly, plId, AcDb::kForRead);
poly->intersectWith(lQieXian, AcDb::Intersect::kExtendArg, ptJdArr2, , ); poly->close(); if (ptJdArr2.length() < ) { lQieXian->close();
break; } lQieXian->close(); } acdbOpenObject(lQieXian, qxId, AcDb::kForWrite); es = acdbOpenObject(poly, plId, AcDb::kForRead); ptJdArr.removeAll(); poly->intersectWith(lQieXian, AcDb::Intersect::kExtendArg, ptJdArr, , ); AcGePoint3d preCenter;
if (ptJdArr.length() >= ) { AcDbLine* lFg = new AcDbLine(ptJdArr[], ptJdArr[]); preCenter = AcGePoint3d((ptJdArr[].x + ptJdArr[].x) / , (ptJdArr[].y + ptJdArr[].y) / , );
lFg->setColorIndex(); CDwgDataBaseUtil::PostToModelSpace(lFg); lFg->close(); }
else { poly->close();
lQieXian->erase();
lQieXian->close();
lQieXian = NULL;
//ptId = CDwgDataBaseUtil::PostToModelSpace(ptPy);
return; } poly->close(); AcDbPolyline *pCopyQx = (AcDbPolyline*)lQieXian->clone(); pCopyQx->transformBy(AcGeMatrix3d::translation(pyXl.normal() *bujin)); if (i != (int)vecArea.size() - ) { es = acdbOpenObject(poly, plId, AcDb::kForRead); ptJdArr.removeAll(); poly->intersectWith(pCopyQx, AcDb::Intersect::kExtendArg, ptJdArr, , ); if (ptJdArr.length() >= ) {
ptQieDian = AcGePoint3d((ptJdArr[].x + ptJdArr[].x) / , (ptJdArr[].y + ptJdArr[].y) / , ); ptQieDian = AcGePoint3d((preCenter.x + ptQieDian.x) / , (preCenter.y + ptQieDian.y) / , ); }
qxId = CDwgDataBaseUtil::PostToModelSpace(pCopyQx); pCopyQx->close();
poly->close();
pCopyQx = NULL;
}
lQieXian->erase();
lQieXian->close();
lQieXian = NULL; //当运行到最后一个面积时,就不复制了
if (i == (int)vecArea.size() - ) { delete pCopyQx;
pCopyQx = NULL; break;
}
} /*if (ptId.isNull()) {
ptId = CDwgDataBaseUtil::PostToModelSpace(ptPy);
ptPy->close();
}*/
}
构造函数:
CAreaFenGe::CAreaFenGe(ACHAR *fenGeStr, AcDbPolyline *&p, AcDbLine *&l)
{ vector<CString> vec; CStringUtil::Split(W2T(fenGeStr), L",", vec, false); for (int i = ; i < (int)vec.size(); i++)
{
vecFenGe.push_back(_wtof(vec.at(i)));
}
this->poly = p;
this->line = l; l1Pt = l->startPoint();
l2Pt = l->endPoint(); if (poly->isClosed() == false) {
poly->setClosed(true);
} poly->getArea(totalArea); for (int i = ; i < (int)vecFenGe.size(); i++)
{
vecArea.push_back(totalArea*vecFenGe.at(i));
acutPrintf(L"%.2f", vecArea[i]);
}
GetDirection();
plId = poly->objectId();
}
objectarx 按比例分割封闭多段线的更多相关文章
- Objectarx 相交矩形求并集 面域转多段线
测试结果: 主要思路:拾取一个点作为矩形的插入点,分别以该点进行两次jig操作,就能得到白色的两个相交的polyline,之后需要变成红色的封闭多段线.做法就是:求出两个白色矩形的面域,然后通过boo ...
- objectarx 多段线自交检查
只支持直线段的多段线检查,因为主要用了初中的知识,一元一次方程求交点,详细的说就是,把多段线上相邻的两个点构成一条直线段,然后每条直线段与剩余的直线段求交点,一条直线段就代表一个一元一次方程,知道两点 ...
- objectarx 填充的分割
主要思路:找到填充边界集合:vecBo,然后把面积最大的边界找出来:bo1,用分割曲线和bo1通过boundary命令构成两个新的最大封闭边界,左边的记为 boLeft(红色部分),右边的记为boRi ...
- ArcGIS AddIn 图斑比例分割工具,调用捕捉功能
最近做一个图斑按比例分割的工具,需要绘制一条用以切割的方向线,通过Tool的方式实现 绘制时希望能够使用捕捉功能,查阅相关资料如下: 使用该文章,第Implementing snapping in a ...
- arcgis 按面积分割, 按比例分割面积,按等份批量面积分割工具
arcgis 按面积分割, 按比例分割面积,按等份批量面积分割工具 视频下载:https://yunpan.cn/cvujkpKIqwccn 访问密码 e9f4
- Java 直线、多段线画板 PaintJFrame (整理)
package demo; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; impor ...
- Cesium实现文字、点、多段线、多边形的实时绘制
背景知识 点.线.面以及文字的实时绘制是GIS很重要的一个功能,是用户对感兴趣区域标注的业务需要.同时Cesium提供了点.线(多段线).面及文字(label)绘制的接口,绘制方式总共有两种,一种是通 ...
- 4、c++ Arx二次开发创建多段线
一.本节课程 c++ Arx二次开发创建多段线 二.本节要讲解的知识点 如何应用C++ ARX二次开发创建多段线(AcDbPolyline.AcDb2dPolyLine.AcDb3dPolyline的 ...
- CAD交互绘制多段线(网页版)
多段线又被称为多义线,表示一起画的都是连在一起的一个复合对象,可以是直线也可以是圆弧并且它们还可以加不同的宽度. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下 ...
随机推荐
- H3C 链路聚合分类
- vue项目上滑滚动加载更多&下拉刷新
上滑滚动时获取内容高度.屏幕高度和滚动高度(此处#sslist要为内容是id) 内容高度 let innerHeight = document.querySelector("#sslist ...
- MockMvc control层单元测试 参数传递问题
GET: 1.路径参数@PathVariable 2.表单参数@RequestParam POST: 1.JSON请求体参数 @RequestBody 放: 1.路径参数@PathVariable 2 ...
- 【t050】方程求解
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 要求Xi(i = 1,2,3,4)是一个[-T..T]中的整数,满足方程AX1 + BX2 + CX3 ...
- 2018-11-13-WPF-禁用实时触摸
title author date CreateTime categories WPF 禁用实时触摸 lindexi 2018-11-13 10:45:37 +0800 2018-5-4 21:0:3 ...
- quartz关闭DBUG日志
引用了Quartz组件后,打印日志时,整天都有相应的调试信息打印出来,严重影响了查找日志效率,谷歌一番后,修改nlog配置文件即可 <?xml version="1.0" e ...
- ERROR StatusLogger Log4j2 could not find a logging implementation.
今天在学习structs2 2.5.5的版本的时候碰到2个问题.第一个网上下的包里面差log4j-core这个包. 虽然程序可以运行,但控制台会报这个错误. ERROR StatusLogger L ...
- Struts2 类型转换(易百教程)
在HTTP请求中的一切都被视为一个String由协议.这包括数字,布尔值,整数,日期,小数和一切.每一件事情是一个字符串,将根据HTTP.然而,Struts类可以有任何数据类型的属性.Struts的自 ...
- Python之time模块和datatime模块
import time time.sleep(5) #休眠 time.time() #返回系统时间戳 utc时间秒数 time.ctime() #返回字符串时间格式,也可以传入参数转换为字符串时间ti ...
- MySQL基础篇(03):系统和自定义函数总结,触发器使用详解
本文源码:GitHub·点这里 || GitEE·点这里 一.系统封装函数 MySQL 有很多内置的函数,可以快速解决开发中的一些业务需求,大概包括流程控制函数,数值型函数.字符串型函数.日期时间函数 ...