MATLAB:通过打开创建Delaunay三角剖分 [英] MATLAB: Create Delaunay Triangulation with Opening
问题描述
我有一个多边形,该多边形的顶点为V
,开口数为n
.如何在MATLAB中使用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?
我知道我可以使用 delaunay 功能,但我不知道如何输入开头.
I know I can use the delaunay function, but I don't know how to input the opening.
推荐答案
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.
您可以使用函数 DelaunayTri 来创建Delaunay三角剖分边被限制为包括多边形的边界和开口的边.这将创建一个包含开口的三角剖分,因此您可以使用
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:
这篇关于MATLAB:通过打开创建Delaunay三角剖分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!