2017-05-28 127 views
1

我想使用delaunay函數對區域L =(-1,1)^ 2 \ [0,1)^ 2進行三角剖分,但似乎無法使其工作。L形區域的三角剖分

我所做的就是簡單地使用meshgrid在左側L的矩形區域:

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

,並在第4象限中的正方形區域:

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

然後串聯的兩個,並稱這兩個函數的delaunay函數,但是,這不會產生預期的結果,因爲我有例如連接點(1,0)和(0,1)的三角形側。

有人知道如何對這個L形區域進行三角測量嗎?

回答

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 trinagle 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