2009-11-09 157 views

回答

5

注意:較新版本的MATLAB推薦使用delaunayTriangulation class及其相關方法。以下解決方案適用於舊版本,並且應該很容易適應較新的類。


您可以使用函數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]); 

,這裏是由上面的代碼創建的情節:

enter image description here

相關問題