您的示例确实为无界单元创建了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'呢? –