L形区域的三角剖分

时间:2017-05-28 15:16:29

标签: matlab

我想使用delaunay函数对区域L =( - 1,1)^ 2 \ [0,1)^ 2进行三角测量,但我似乎无法使其工作。

我所做的只是在L:左侧的矩形区域使用meshgrid

[x_left, y_left] = meshgrid(-1:0.25:0,-1:0.25:1)

并在第四象限的方形区域:

[x_right, y_right] = meshgrid(0:0.25:1,-1:0.25:1)

然后连接这两个并在这两个上调用delaunay函数,但是,这不会产生预期的结果,因为我有例如连接点(1,0)和(0,1)的三角形边。

有人知道如何对这个L形区域进行三角测量吗?

1 个答案:

答案 0 :(得分:3)

我使用inpolygon找到包含在L形状中的三角形中心:

% generate grid on [-1 1] interval
[xg,yg] = meshgrid(linspace(-1,1));
% coordinates of L corners
x = [-1 0 0 1 1 -1].';
y = [-1 -1 0 0 1 1].';
% generate L binary mask using inpolygon
[IN,ON] = inpolygon(xg,yg,x,y);
bw = IN | ON;
% triangulate L corners
TRI = delaunay(x,y);
% get triangle centers coordinates
c = [mean(x(TRI),2) mean(y(TRI),2)];
% check if centers inside L
IN = inpolygon(c(:,1),c(:,2),x,y);
% remove triangles whose centers outside L
TRI = TRI(IN,:);
% visualize
imshow(bw,'XData',[-1 1],'YData',[-1 1],'InitialMagnification','fit');
hold on;
triplot(TRI,x,y,'LineWidth',2);

enter image description here