selective direction for voronoi diagram in matlab -


how can create voronoi diagram on these squares in matlab, voronoi not enter yellow square? alternatively, lines of enters yellow ones.

enter image description here

it possible put constrains on delaunay triangulation, , add more checks afterwards. maybe can you:

close % 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 [xmin ymin xmax ymax] format boxes = [rects(:,1:2), rects(:,1:2) + rects(:,3:4)]; % convert 1 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 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 rectangles xeq = bsxfun(@eq,xi,xi'); yeq = bsxfun(@eq,yi,yi'); xyeq = triu(xeq | yeq,1); [idx1,idx2] = find(xyeq); % generate constrains triangulation c = [idx1,idx2]; % triangulate dt = delaunaytriangulation([xi,yi],c); % connections (triangles) list tri = dt.connectivitylist; remidx = false(size(tri,1),1); % check condition remove triangles 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


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -