MATLAB: Overlapping polygons translation to non overlapping polygons

overlappingpolygons

how can i translate the overlapping polygos to new location so that there is no overlap.
A=[];
N = 20;
for i=1:N
X = randn(N,2);
R = sqrt(rand(N,1));
X = R .* X ./ sqrt(sum(X.^2,2));
X=.05.*X;
XX=X(:,1);
XY=X(:,2);
XX=XX+rand;
XY=XY+rand;
K=convhull(XX,XY);
polyin=polyshape(XX(K),XY(K));
polyarray=regions(polyin);
AB=[XX(K),XY(K)];
A=[A; AB];
plot(XX(K),XY(K));
hold on
end
Capture.PNG

Best Answer

c(i)=polyin;
AB=[XX(K),XY(K)];
A{i} = AB;
TF = overlaps(c);
end
[R, C] = find(TF);
A(R(~(R==C))) = [];
for i = A
plot(i{:}(:,1), i{:}(:,2))
hold on;
end