One very general way is to just keep generating shapes randomly but throw away any newly-generated random shapes that overlap with ones you have previously generated. The algorithm might look something like this:
PixelUsed = false(n,n);
while WantMoreShapes
newShape = myRandomShapeGenerator;
thisShapePixel = PixelMarker(newShape);
if ~AnyOverlap(thisShapePixel,PixelUsed)
iShape = iShape + 1;
myStoreShape(iShape) = newShape;
PixelUsed = PixelUsed | thisShapePixel;
WantMoreShapes = ???;
end
end
Watch out---this process could easily get into an infinite loop, so you should add code to exit after a number of unsuccessful newShape's.
Also, the shapes generated later will tend to be smaller (since larger ones are more likely to overlap with something). If that is a problem for you, then this method probably won't work.
Best Answer