开发者

MATLAB: Create Delaunay Triangulation with Opening

I have a polygon with V vertices and n number of openings. How can I create a mesh using Delaunay triangulat开发者_运维知识库ion for this polygon in MATLAB?

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.


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: Create Delaunay Triangulation with Opening

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜