Matlab之创建和编辑Delaunay三角剖分

2025-10-31 21:28:46

1、示例一:创建并绘制2D Delaunay三角剖分

本示例说明如何计算2D Delaunay三角剖分以及如何将三角剖分与顶点和三角形标签一起绘制。

在命令行窗口,输入命令:

x = rand(10,1);

y = rand(10,1);

dt = delaunayTriangulation(x,y)

按“Enter键”。

如图1所示。

Matlab之创建和编辑Delaunay三角剖分

2、在命令行窗口,输入命令:

triplot(dt);

%

% Display the Vertex and Triangle labels on the plot

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

按“Enter键”。

如图2所示。

Matlab之创建和编辑Delaunay三角剖分

3、示例二:创建并绘制3D Delaunay三角剖分

本示例向您展示如何计算3D Delaunay三角剖分以及如何绘制三角剖分。

在命令行窗口,输入命令:

X = rand(10,3)

按“Enter键”。

如图3所示。

Matlab之创建和编辑Delaunay三角剖分

4、在命令行窗口,输入命令:

dt = delaunayTriangulation(X)

按“Enter键”。

如图4所示。

Matlab之创建和编辑Delaunay三角剖分

5、在命令行窗口,输入命令:

tetramesh(dt, 'FaceColor', 'cyan');

% To display large tetrahedral meshes use the convexHull method to

% compute the boundary triangulation and plot it using trisurf.

% For example;

% triboundary = convexHull(dt)

% trisurf(triboundary, X(:,1), X(:,2), X(:,3), 'FaceColor', 'cyan')

按“Enter键”。

如图5所示。

Matlab之创建和编辑Delaunay三角剖分

6、示例三:访问三角剖分数据结构

有两种方法可以访问三角测量数据结构。 一种方法是通过Triangulation属性,另一种方法是使用索引。

从10个随机点创建2D Delaunay三角剖分。

在命令行窗口,输入命令:

X = rand(10,2)

按“Enter键”。

如图6所示。

Matlab之创建和编辑Delaunay三角剖分

7、在命令行窗口,输入命令:

dt = delaunayTriangulation(X)

按“Enter键”。

如图7所示。

Matlab之创建和编辑Delaunay三角剖分

8、在命令行窗口,输入命令:

% The triangulation datastructure is;

dt.ConnectivityList

按“Enter键”。

如图8所示。

Matlab之创建和编辑Delaunay三角剖分

9、在命令行窗口,输入命令:

% Indexing is a shorthand way to query the triangulation. The format is

% dt(i, j) where j is the j'th vertex of the i'th triangle, standard

% indexing rules apply.

% The triangulation datastructure is

dt(:,:)

按“Enter键”。

如图9所示。

Matlab之创建和编辑Delaunay三角剖分

10、第二个三角形是;

在命令行窗口,输入命令:

dt(2,:)

按“Enter键”。

如图10所示。

Matlab之创建和编辑Delaunay三角剖分

11、第二个三角形的第三个顶点是;

在命令行窗口,输入命令:

dt(2,3)

按“Enter键”。

如图11所示。

Matlab之创建和编辑Delaunay三角剖分

12、前三个三角形;

在命令行窗口,输入命令:

dt(1:3,:)

按“Enter键”。

如图12所示。

Matlab之创建和编辑Delaunay三角剖分

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢