MATLAB: How to add shadings when overlapping polygons

MATLABoverlapping polygonspolygonspolyshape

Polygons.jpg
figure();
x = [0 1 1 0];
y = [0 0 1 1];
xy = polyshape(x,y); hold on;
xx = [0 0.5 0.5 0];
yy = [0 0 0.5 0.5];
xxyy = polyshape(xx,yy);
xxx = [0.25 0.75 0.75 0.25];
yyy = [0.25 0.25 0.75 0.75];
xxxyyy = polyshape(xxx,yyy);
L = linspace(0,2.*pi,100);
kx = 0.2*cos(L)'+0.7;
ky = 0.2*sin(L)'+0.7;
kreis = polyshape(kx(1:end-1),ky(1:end-1));
plot(xy)
plot(xxyy)
plot(xxxyyy)
plot(kreis)
axis equal;
I have a variety of polygons. Now I need to know how to either shade the overlapping areas according to a grayscale (the the more polygons overlapping the darker the intersecting area) or to otherwise gain information about the overlapping areas. Thanks

Best Answer

Why not just create a grayscale image?
t= linspace(0,1,300);
[X,Y]=meshgrid(t);
sz=size(X);
X=X(:);Y=Y(:);
I=xy.isinterior(X,Y)+xxyy.isinterior(X,Y)+xxxyyy.isinterior(X,Y)+...
kreis.isinterior(X,Y);
imagesc((reshape(I,sz)),'XData',t,'YData',t);
colormap(gray)
axis image
set(gca,'YDir','normal');