algorithm - random placement of rectangles with no overlaps -


i looking sound algorithm randomly place given number of rectangles of same size bigger rectangle (canvas).

i see 2 ways it:

  1. create empty array contain rectangles placed on canvas. start empty canvas. in loop, pick position @ random new rectangle placed. check if array has rectangle overlaps new rectangle. if not, put new rectangle in array , repeat loop. otherwise, pick new position, , rerun check again. , on. might never terminate (theoretically) think. not it.

  2. use grid , place rectangles cells randomly. might still grid placement. not either.

any better ways it? "better" meaning more efficient, or more visually "random" grid approach. better in respect.

here simple heuristic. non-overlapping , random.

place rectangle randomly. then, calculate intersections of extensions of the 2 parallel edges of first rectangle edges of canvas. obtain 4 convex empty regions. place other rectangles in these empty regions one-by-one independently , calculate similar divisions placements. , try put remaining rectangles in empty regions.

you can try different strategies. can try place rectangles close corners. or, can place them around center of regions. cannot discuss optimality because introduced randomness.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -