CGAL求最小外包矩形
有两种所谓的最小外包矩形,第一种通过求所有节点的最小与最大xy来求的,这种叫与坐标轴平行的最小外包矩形;另外一种则是本文说的这种,与范围的形状与走势有关的,叫非坐标轴平行的最小外包矩形,效果如下图所示:
CGAL求最小外包矩形 > image2018-8-21_10-33-22.png
/// 这里做测试,只选中LWPOLYLINLE,也就是CAD中的多段线实体
struct resbuf* rb = ads_buildlist(RTDXF0, _T("LWPOLYLINE"), RTNONE);
ads_name ent, ssLines;
if (RTNORM != ads_ssget(NULL, NULL, NULL, rb, ssLines))
{
ads_relrb(rb);
return;
}
ads_relrb(rb);
AcDbObjectId id;
Adesk::Int32 len = 0, l = 0;
ads_sslength(ssLines, &len);
std::vector<Point_2> nodesn,nodes_hull;
////////这里遍历选择集获取所有实体的节点
for (l = 0;l < len;l++)
{
ads_ssname(ssLines, l, ent);
if (Acad::eOk != acdbGetObjectId(id, ent))
{
continue;
}
AcDbEntity* pEnt = NULL;
if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead) != Acad::eOk)
{
continue;
}
if (!pEnt->isKindOf(AcDbPolyline::desc()))
{
continue;
}
AcDbPolyline* pLine = AcDbPolyline::cast(pEnt);
AcGePoint3d ptS, ptE;
for (int idx = 0;idx < pLine->numVerts();idx++)
{
AcGePoint2d pt;
pLine->getPointAt(idx, pt);
nodesn.push_back(Point_2(pt.x, pt.y));
acutPrintf(_T("Random coordinate:%d: %.3lf %.3lf\n"), idx+1,pt.x, pt.y);
}
pEnt->close();
break;
}
ads_ssfree(ssLines);
///发现在求最小外接矩形的时候传入的点不能有坐标一直的点,而且点的方向必须是逆时针排列
///所以这里先求节点的凸包,然后通过Polygon_2来把非逆时针排列的节点纠正成逆时针
CGAL::convex_hull_2(nodesn.begin(), nodesn.end(), std::back_inserter(nodes_hull));
Polygon_2 p;
std::vector<Point_2>::iterator itn;
for (itn = nodes_hull.begin();itn != nodes_hull.end();itn++)
{
p.push_back(*itn);
}
AcGePoint2dArray nodes;
for (int i = 0;i < p.size();i++)
{
double x = CGAL::to_double(p.vertex(i).x());
double y = CGAL::to_double(p.vertex(i).y());
nodes.append(AcGePoint2d(x, y));
}
Common::DrawPolyline2D(nodes, true);
if (p.is_clockwise_oriented())
{
p.reverse_orientation();
}
Polygon_2 m_p;
CGAL::min_rectangle_2(p.vertices_begin(), p.vertices_end(), std::back_inserter(m_p));
Polygon_2::Vertex_const_iterator it;
nodes.removeAll();
for (it = m_p.vertices_begin(); it != m_p.vertices_end(); it++)
{
double x = CGAL::to_double((*it).x());
double y = CGAL::to_double((*it).y());
nodes.append(AcGePoint2d(x, y));
}
Common::DrawPolyline2D(nodes, true);
CGAL求最小外包矩形的更多相关文章
- CAD在网页中返回当前图纸的最小外包矩形框
主要用到函数说明: _DMxDrawX::GetMcDbDatabaseBound 返回当前图纸的最小外包矩形框,详细说明如下: 参数 说明 DOUBLE* pLbx 返回最小外包矩形框左下角X值 D ...
- TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)
描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...
- [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> # ...
- BZOJ 1185: [HNOI2007]最小矩形覆盖-旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标-备忘板子
来源:旋转卡壳法求点集最小外接矩形(面积)并输出四个顶点坐标 BZOJ又崩了,直接贴一下人家的代码. 代码: #include"stdio.h" #include"str ...
- matlab练习程序(最小包围矩形)
又是计算几何,我感觉最近对计算几何上瘾了. 当然,工作上也会用一些,不过工作上一般直接调用boost的geometry库. 上次写过最小包围圆,这次是最小包围矩形,要比最小包围圆复杂些. 最小包围矩形 ...
- UVA10173 Smallest Bounding Rectangle 最小面积矩形覆盖
\(\color{#0066ff}{题目描述}\) 给定n(>0)二维点的笛卡尔坐标,编写一个程序,计算其最小边界矩形的面积(包含所有给定点的最小矩形). 输入文件可以包含多个测试样例.每个测试 ...
- poj 2185 Milking Grid(next数组求最小循环节)
题意:求最小的循环矩形 思路:分别求出行.列的最小循环节,乘积即可. #include<iostream> #include<stdio.h> #include<stri ...
- Opencv绘制最小外接矩形、最小外接圆
Opencv中求点集的最小外结矩使用方法minAreaRect,求点集的最小外接圆使用方法minEnclosingCircle. minAreaRect方法原型: RotatedRect minAre ...
- LeetCode939 最小面积矩形
LeetCode939最小面积矩形 给定在 xy 平面上的一组点,确定由这些点组成的矩形的最小面积,其中矩形的边平行于 x 轴和 y 轴. 如果没有任何矩形,就返回 0. Input [[1,1],[ ...
- opencv —— boundingRect、minAreaRect 寻找包裹轮廓的最小正矩形、最小斜矩形
寻找包裹轮廓的最小正矩形:boundingRect 函数 返回矩阵应满足:① 轮廓上的点均在矩阵空间内.② 矩阵是正矩阵(矩形的边界与图像边界平行). Rect boundingRect(InputA ...
随机推荐
- 让CSS flex布局最后一行列表左对齐的N种方法
原文链接https://mp.weixin.qq.com/s?__biz=MjM5MDA2MTI1MA==&mid=2649091838&idx=1&sn=fa4e1ed1e0 ...
- css小技巧【让背景最少是屏幕高度】【让三个字和四个字左右对齐】
怎么让背景最少是屏幕高度 min-height: 100vh; 怎么让三个字和四个字左右对齐 text-align-last: justify;
- 数据类型之字符串(string)(一)
1.引号括起的都是字符串(可以时空格),可以是''(单引号).""(双引号).''''''(三引号).""""""(我还 ...
- python列表循环中删除元素
遍历n个元素的列表,每次循环时删除当前元素,那么要多少次结束循环呢. 上一段代码: arr = [0,1,2,3,4] for x in arr: print('本次删除的元素:',x) arr.re ...
- python实现两张图片拼接
纵向拼接 from PIL import Image def image_splicing(pic01, pic02): """ 图片拼接 :param pic01: 图 ...
- 使用shell判断文件夹中是否包含文件
#!/bin/bash directory="/path/to/directory" if [ $(ls -A $directory) ]; then echo "有文件 ...
- 对NAN的认识
NaN是个特殊的数值,它与任何值都不相等,包括它自己,NaN==NaN和NaN===NaN都是false,如果想测试某个数字是否为NaN,可以使用内置的函数isNaN(),如果是NaN则返回true, ...
- Unity打包xcode修改工程配置代码
1 using System.IO; 2 using UnityEngine; 3 using UnityEditor; 4 using UnityEditor.iOS.Xcode; 5 using ...
- driver报错
self.driver = webdriver.Chrome(),突然报错,运行不了 解决办法: 第一步:去检查你以安装的驱动版本,用cmd打开命令提示符:然后用命令:chromedriver 第二步 ...
- docker之rabbitmq delayed message exchange
创建dockerfile FROM rabbitmq:3.9.11-management-alpine COPY rabbitmq_delayed_message_exchange-3.9.0.ez ...