2017-04-14 11 views
0

ボロノイが黄色の四角形に入らないので、MATLABでこれらの四角形にボロノイ図を作成するにはどうすればよいですか?あるいは、それのいくつかのラインが黄色のラインに入る。matlabのボロノイ図の選択方向

enter image description here

+1

あなたはビットを明確にすることはできますか?ボロノイ図の線を矩形にするかどうか分かりません。距離測定の代わりに正方形でボロノイ図を作成したいですか?あなたが得ようとしている種類の出力のスケッチを提供できますか? –

答えて

0

constrains on Delaunay triangulationを入れ、その後多くのチェックを追加することが可能です。多分それはあなたを助けることができる:

close all 
% generate random rectangels [x,y,w,h] format 
n = 8; 
w = 0.15; 
h = 0.05; 
rects = [rand(n,2),w*ones(n,1),h*ones(n,1)]; 
% convert to [xmin ymin xmax ymax] format 
boxes = [rects(:,1:2), rects(:,1:2) + rects(:,3:4)]; 
% convert to one single polygon (with missing vertexes) 
X = boxes(:,[1 3 3 1 1]); 
Y = boxes(:,[2 2 4 4 2]); 
X(:,end+1) = nan; 
Y(:,end+1) = nan; 
X = X';X = X(:); 
Y = Y';Y = Y(:); 
% polygon vertxes without the Nans 
XX = X;XX(6:6:end) = []; 
YY = Y;YY(6:6:end) = []; 
% intersections between rectangles 
[xi,yi] = polyxpoly(X,Y,X,Y,'unique'); 
% remove intersections found inside rectangles 
IN = any(bsxfun(@gt,xi',boxes(:,1)) & bsxfun(@lt,xi',boxes(:,3)) & ... 
    bsxfun(@gt,yi',boxes(:,2)) & bsxfun(@lt,yi',boxes(:,4)),1); 
xi(IN) = []; 
yi(IN) = []; 
% find vertex pairs of the rectangles 
xeq = bsxfun(@eq,xi,xi'); 
yeq = bsxfun(@eq,yi,yi'); 
xyeq = triu(xeq | yeq,1); 
[idx1,idx2] = find(xyeq); 
% generate constrains for the triangulation 
C = [idx1,idx2]; 
% triangulate 
DT = delaunayTriangulation([xi,yi],C); 
% get connections (triangles) list 
TRI = DT.ConnectivityList; 
remIdx = false(size(TRI,1),1); 
% check condition to remove triangles 
for ii = 1:size(TRI,1) 
    % current triangle coordinates 
    xx = xi(TRI(ii,[1:3 1])); 
    yy = yi(TRI(ii,[1:3 1])); 
    % find if triangle inside rectangle 
    BETx = bsxfun(@ge,xx(1:3)',boxes(:,1)) & bsxfun(@le,xx(1:3)',boxes(:,3)); 
    BETy = bsxfun(@ge,yy(1:3)',boxes(:,2)) & bsxfun(@le,yy(1:3)',boxes(:,4)); 
    IN = BETx & BETy; 
    if any(all(IN,2)) 
     remIdx(ii) = true; 
     continue; 
    end 
    % find if triangle crosses rectangle 
    [xxi,yyi] = polyxpoly(xx,yy,X,Y,'unique'); 
    notAllowedVertex = ~ismember([xxi yyi],[xi,yi],'rows'); 
    if any(notAllowedVertex) 
     remIdx(ii) = true; 
     continue; 
    end 
end 
% remove unwanted triangles 
TRI(remIdx,:) = []; 
% plot 
figure; 
hold on 
plot(X,Y,'g','LineWidth',2) 
triplot(TRI,xi,yi) 
plot(xi,yi,'or') 
axis equal 

enter image description here

+0

残念ながら私は専門的にはMatlabを使用していないので、私はあなたのコードを使用することができませんでした。ところで、ご注意いただきありがとうございます – Azadeh

関連する問題