MATLAB: Create Delaunay Triangulation with Opening

前端 未结 1 443
醉梦人生
醉梦人生 2020-12-21 04:05

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?

相关标签:
1条回答
  • 2020-12-21 04:37

    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:

    0 讨论(0)
提交回复
热议问题