MATLAB: Create Delaunay Triangulation with Opening

守給你的承諾、 提交于 2019-12-18 08:49:32

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/1700522/matlab-create-delaunay-triangulation-with-opening

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!