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 绘制一个直线.详细说明如下 ...
随机推荐
- 2018-11-19-win10-uwp-使用-AppCenter-自动构建
title author date CreateTime categories win10 uwp 使用 AppCenter 自动构建 lindexi 2018-11-19 15:29:34 +080 ...
- POJ 1511 Invitation Cards(逆向思维 SPFA)
Description In the age of television, not many people attend theater performances. Antique Comedians ...
- ZR1050
ZR1050 http://www.zhengruioi.com/problem/1030 题目大意: 给定一棵带点权的树,求所有联通块的点权和的平方的和 \(n \le 10^5\) 题解 首先,关 ...
- springBoot中使用使用junit测试文件上传,以及文件下载接口编写
本篇文章将介绍如何使junit在springBoot中测试文件的上传,首先先阅读如何在springBoot中进行接口测试. 文件上传操作测试代码 import org.junit.Before; im ...
- CentOS服务器安装mysql
1.配置YUM源 下载mysql源安装包 [root@localhost~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8 ...
- es6笔记 day4---模块化
模块化: 注意:需要放到服务器环境 1.如何定义模块? export 东西 export const a = 12; export { a as aaa, b as banana } 2 ...
- 【42.49%】【hdu 1542】Atlantis(线段树扫描线简析)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- codeforces 1183F 离散化枚举 约数定理
codeforces1183F 有技巧的暴力 传送门:https://codeforces.com/contest/1183/problem/F 题意: 给你n个数,要你从中选出最多三个数,使得三个数 ...
- Linux统计文件/目录数量ls -l | grep "^-" | wc -l匹配开头和结尾,wc -c统计字符串长度
Linux统计文件数量 ls -l | grep "^-" | wc -l “^-” 一般文件 “^d” 目录文件 shell/vim中^表示开头 cat repatterns ...
- Android1_运行第一个AS项目HelloWorld
一.开发安卓程序需要具备一些开发工具,这里简单罗列一下: JDK :这是Java语言的开发工具包,包含了Java的运行环境.工具集合.基础类库等内容. Android Studio:目前主流的安卓开发 ...