创建和编辑 Delaunay 三角剖分 您所在的位置:网站首页 matlab三角函数命令 创建和编辑 Delaunay 三角剖分

创建和编辑 Delaunay 三角剖分

2023-06-10 03:26| 来源: 网络整理| 查看: 265

示例一:创建和绘制二维 Delaunay 三角剖分

此示例说明如何计算二维 Delaunay 三角剖分,然后同时对三角剖分以及顶点和三角标签绘图。

rng default x = rand(10,1); y = rand(10,1); dt = delaunayTriangulation(x,y)dt = delaunayTriangulation with properties: Points: [10x2 double] ConnectivityList: [11x3 double] Constraints: [] triplot(dt)

在图上显示顶点和三角标签。

hold on vxlabels = arrayfun(@(n) {sprintf('P%d', n)}, (1:10)'); Hpl = text(x,y,vxlabels,'FontWeight','bold','HorizontalAlignment',... 'center','BackgroundColor','none'); ic = incenter(dt); numtri = size(dt,1); trilabels = arrayfun(@(x) {sprintf('T%d',x)}, (1:numtri)'); Htl = text(ic(:,1),ic(:,2),trilabels,'FontWeight','bold', ... 'HorizontalAlignment','center','Color','blue'); hold off

示例二:创建和绘制三维 Delaunay 三角剖分

此示例说明如何计算和绘制三维 Delaunay 三角剖分。

rng default X = rand(10,3); dt = delaunayTriangulation(X)dt = delaunayTriangulation with properties: Points: [10x3 double] ConnectivityList: [18x4 double] Constraints: [] tetramesh(dt) view([10 20])

要显示大型四面体网格,请使用 convexHull 方法计算边界三角剖分,并使用 trisurf 对其绘图。例如:

triboundary = convexHull(dt); trisurf(triboundary, X(:,1), X(:,2), X(:,3),'FaceColor','cyan') 示例三:访问三角剖分数据结构体

可通过两种方式访问三角剖分数据结构。一种方式是通过 Triangulation 属性,另一种方式是使用索引。

基于 10 个随机点创建一个二维 Delaunay 三角剖分。

rng default X = rand(10,2); dt = delaunayTriangulation(X)dt = delaunayTriangulation with properties: Points: [10x2 double] ConnectivityList: [11x3 double] Constraints: []

访问三角剖分数据结构体的一种方式是使用 ConnectivityList 属性。

dt.ConnectivityListans = 11×3 2 8 5 7 6 1 3 7 8 8 7 5 3 8 2 6 7 3 7 4 5 5 9 2 2 9 10 5 4 9 ⋮

使用索引是查询三角剖分的一种简便方式。语法为 dt(i,j),其中 j 是第 i 个三角形的第 j 个顶点。需遵循标准索引规则。

使用索引查询三角剖分数据结构体。

dt(:,:)ans = 11×3 2 8 5 7 6 1 3 7 8 8 7 5 3 8 2 6 7 3 7 4 5 5 9 2 2 9 10 5 4 9 ⋮

第二个三角形为:

dt(2,:)ans = 1×3 7 6 1

第二个三角形的第三个顶点为:

dt(2,3)ans = 1

前三个三角形为:

dt(1:3,:)ans = 3×3 2 8 5 7 6 1 3 7 8 示例四:编辑 Delaunay 三角剖分以插入或删除点

下面的示例说明了如何使用基于索引的下标插入或删除点。相对于从头重新创建新的 delaunayTriangulation,编辑 delaunayTriangulation 以进行少量修改的效率更高,数据集较大时尤其如此。

基于单位正方形内的 10 个随机点构造一个 Delaunay 三角剖分。

rng default x = rand(10,1); y = rand(10,1); dt = delaunayTriangulation(x,y)dt = delaunayTriangulation with properties: Points: [10x2 double] ConnectivityList: [11x3 double] Constraints: []

插入 5 个其他随机点。

dt.Points(end+(1:5),:) = rand(5,2)dt = delaunayTriangulation with properties: Points: [15x2 double] ConnectivityList: [20x3 double] Constraints: []

替换第五个点。

dt.Points(5,:) = [0 0]dt = delaunayTriangulation with properties: Points: [15x2 double] ConnectivityList: [20x3 double] Constraints: []

删除第四个点。

dt.Points(4,:) = []dt = delaunayTriangulation with properties: Points: [14x2 double] ConnectivityList: [18x3 double] Constraints: [] 示例五:创建有约束 Delaunay 三角剖分

此示例说明如何创建一个有约束 Delaunay 三角剖分,并说明约束的影响。

创建并绘制一个有约束 Delaunay 三角剖分。

X = [0 0; 16 0; 16 2; 2 2; 2 3; 8 3; 8 5; 0 5]; C = [1 2; 2 3; 3 4; 4 5; 5 6; 6 7; 7 8; 8 1]; dt = delaunayTriangulation(X,C); subplot(2,1,1) triplot(dt) axis([-1 17 -1 6]) xlabel('Constrained Delaunay triangulation','FontWeight','b')

用红色绘制约束边。

hold on plot(X(C'),X(C'+size(X,1)),'-r','LineWidth',2) hold off

现在删除约束并绘制无约束 Delaunay 三角剖分。

dt.Constraints = []; subplot(2,1,2) triplot(dt) axis([-1 17 -1 6]) xlabel('Unconstrained Delaunay triangulation','FontWeight','b')

示例六:创建地图的有约束 Delaunay 三角剖分

加载美国本土的周长地图。构造一个受约束的代表该多边形的 Delaunay 三角剖分。该三角剖分跨受点集的凸包约束的一个域。过滤出多边形域内的三角形并对其绘图。注意:该数据集包含重复的数据点;即两个或更多个数据点的位置相同。重复的点将被拒绝,delaunayTriangulation 会相应地重新设置约束的格式。

clf load usapolygon

在构成多边形边界的两个连续点之间定义一个边约束,并创建 Delaunay 三角剖分。

nump = numel(uslon); C = [(1:(nump-1))' (2:nump)'; nump 1]; dt = delaunayTriangulation(uslon,uslat,C);Warning: Duplicate data points have been detected and removed. The Triangulation indices and constraints are defined with respect to the unique set of points in delaunayTriangulation. Warning: Intersecting edge constraints have been split, this may have added new points into the triangulation. io = isInterior(dt); patch('Faces',dt(io,:),'Vertices',dt.Points,'FaceColor','r') axis equal axis([-130 -60 20 55]) xlabel('Constrained Delaunay Triangulation of usapolygon','FontWeight','b')

示例七:基于点云重新构造曲线

下面的示例重点介绍如何使用 Delaunay 三角剖分从点云重新构造多边形边界。重新构造操作基于精心设计的 Crust 算法。

参考资料:N. Amenta、M. Bern 和 D. Eppstein。The crust and the beta-skeleton: combinatorial curve reconstruction.Graphical Models and Image Processing, 60:125-135, 1998.

创建一组表示点云的点。

numpts = 192; t = linspace( -pi, pi, numpts+1 )'; t(end) = []; r = 0.1 + 5*sqrt( cos( 6*t ).^2 + (0.7).^2 ); x = r.*cos(t); y = r.*sin(t); ri = randperm(numpts); x = x(ri); y = y(ri);

构造该点集的 Delaunay 三角剖分。

dt = delaunayTriangulation(x,y); tri = dt(:,:);

将 Voronoi 顶点的位置插入现有三角剖分中。

V = voronoiDiagram(dt);

删除无限顶点并用 unique 筛除重复点。

V(1,:) = []; numv = size(V,1); dt.Points(end+(1:numv),:) = unique(V,'rows');

连接成对采样点的 Delaunay 边表示边界。

delEdges = edges(dt); validx = delEdges(:,1)


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有