MATLAB:创建带开口的 Delaunay 三角剖分

发布于 2024-08-10 18:22:43 字数 250 浏览 2 评论 0原文

我有一个具有 V 个顶点和 n 个开口的多边形。如何在 MATLAB 中使用 Delaunay 三角剖分为此多边形创建网格?

我知道我可以使用 delaunay 函数,但是我不知道如何输入开头。

I have a polygon with V vertices and n number of openings. How can I create a mesh using Delaunay triangulation for this polygon in MATLAB?

I know I can use the delaunay function, but I don't know how to input the opening.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-08-17 18:22:43

注意:较新版本的 MATLAB 建议使用 delaunayTriangulation 及其关联方法。下面的解决方案对于旧版本有效,并且应该很容易适应新的类。


您可以使用函数 DelaunayTri 创建带有边的 Delaunay 三角剖分限制为包括多边形的边界和开口的边缘。这将创建一个包含开口的三角剖分,因此您可以使用函数 inOutStatus

这是带有方孔的正方形的示例:

x = [0 1 2 3 3 3 3 2 1 0 0 0 1 2 2 1].';
y = [0 0 0 0 1 2 3 3 3 3 2 1 1 1 2 2].';
c = [(1:11).' (2:12).'; 12 1; (13:15).' (14:16).'; 16 13];  % Constrained edges
dt = DelaunayTri(x, y, c);   % Create constrained triangulation
isInside = inOutStatus(dt);  % Find triangles inside the constrained edges
tri = dt(isInside, :);       % Get end point indices of the inner triangles
triplot(tri, x, y);          % Plot the inner triangles
hold on;
plot(x(c(1:12, :)), y(c(1:12, :)), 'r', 'LineWidth', 2);    % Plot the outer edges
plot(x(c(13:16, :)), y(c(13:16, :)), 'r', 'LineWidth', 2);  % Plot the inner edges
axis equal;
axis([-0.5 3.5 -0.5 3.5]);

这是由上述代码创建的图:

在此处输入图像描述

Note: Newer versions of MATLAB recommend using the delaunayTriangulation class and its associated methods. The solution below is valid for older versions, and should be easy to adapt to the newer class.


You can use the function DelaunayTri to create a Delaunay triangulation with the edges constrained to include the boundary of the polygon and the edges of the openings. This will create a triangulation that includes the openings, so you can then select only those triangles that are "inside" the bounded region (i.e. in the polygon but not in the openings) by using the function inOutStatus.

Here's an example of a square with a square hole:

x = [0 1 2 3 3 3 3 2 1 0 0 0 1 2 2 1].';
y = [0 0 0 0 1 2 3 3 3 3 2 1 1 1 2 2].';
c = [(1:11).' (2:12).'; 12 1; (13:15).' (14:16).'; 16 13];  % Constrained edges
dt = DelaunayTri(x, y, c);   % Create constrained triangulation
isInside = inOutStatus(dt);  % Find triangles inside the constrained edges
tri = dt(isInside, :);       % Get end point indices of the inner triangles
triplot(tri, x, y);          % Plot the inner triangles
hold on;
plot(x(c(1:12, :)), y(c(1:12, :)), 'r', 'LineWidth', 2);    % Plot the outer edges
plot(x(c(13:16, :)), y(c(13:16, :)), 'r', 'LineWidth', 2);  % Plot the inner edges
axis equal;
axis([-0.5 3.5 -0.5 3.5]);

And here's the plot created by the above code:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文