您的示例確實爲無界單元創建了patch
對象,但由於它們包含的頂點具有表示無界邊的Inf
值,因此不會顯示它們。您需要用有限的頂點替換這些頂點來完成修補程序。
由voronoi
生成的繪製無界單元邊的頂點對於此目的很有用。繪製Voronoi圖時,您可以獲取這些:
h = voronoi(D);
v1 = shiftdim(reshape([h(2).XData;h(2).YData],2,3,[]),2); % Arranged one edge per row, one vertex per slice in the third dimension
的無界邊緣最後繪製,因此您可以通過在c
計數無限細胞中分離出這些:
nUnbounded = sum(cellfun(@(ic)ismember(1,ic),c));
v1Unbounded = v1(end-(nUnbounded-1):end,:,:);
這些邊緣的第一家上市的頂點是細胞的有限頂點。這些並不總是完全匹配由於浮點錯誤由voronoin
返回的座標,因此確定通過在從pdist2
最小成對距離,編號爲頂點,這些對應於:
[~,iBounded] = min(pdist2(v,v1Unbounded(:,:,1))); % Index of the bounded vertex
vUnbounded = v1Unbounded(:,:,2); % Displayed coordinate of the unbounded end of the cell edge
要替換這些座標,你可以然後更換patch(v(c{l},1),v(c{l},2),col);
下列要求:
cPatch = c{l}; % List of vertex indices
vPatch = v(cPatch,:); % Vertex coordinates which may contain Inf
idx = find(cPatch==1); % Check if cell has unbounded edges
if idx
cPatch = circshift(cPatch,-idx); % Move the 1 to the end of the list of vertex indices
vPatch = [vPatch(1:idx-1,:)
vUnbounded(iBounded == cPatch(end-1),:)
vUnbounded(iBounded == cPatch(1),:)
vPatch(idx+1:end,:)]; % Replace Inf values at idx with coordinates from the unbounded edges that meet the two adjacent finite vertices
end
patch(vPatch(:,1),vPatch(:,2),col);
能否請您添加TheNumberOfSets','PointsInSet','l','v','C','col'的'樣本信息,以及任何我可能已經錯過了?請參閱[mcve]上的幫助文件(http://stackoverflow.com/help/mcve)以獲取有關如何針對問題製作正確示例的更多信息。 –
我已經添加了更多信息。 @FranzHahn –
'l'呢? –