Reputation: 5954
I'm looking for an algorithm, which randomly distributes a number of rectangles (which are defined by their width and height) inside a container rectangle. The later is not defined by size, rather by it's aspect ratio. There must be one more variable that determines the density of the result, or in other words: the average distance of two rectangles. All rectangles are to be placed, which is possible, because the container is not limited in size. And there must be no overlapping of any rectangles.
The final result should be the determined position for each rectangle as well as the size of the used plane itself.
Unfortunately, I could not find an algorithm that does this, or parts of it until now. I'd appreciate any suggestions, comments or references! It turns out that the main problem is to keep track of a list of "free spaces", which is updated after each placement accordingly.
In the real case I need this for, the given rectangles are not completely randomly shaped. They have almost the same height, and tend to be much broader than tall: They are just words taken from a text which should be distributed over a plane as a "cloud".
Upvotes: 2
Views: 219
Reputation: 36431
I think that you are looking for some thing like graph visualization with a forced-based layout. If you can model a relation in between your words, then the force is the parameter you need.
Upvotes: 0
Reputation:
Here's a few thoughts on how to design an algorithm:
rowCount * colCount == totalCount
and colCount / rowCount == aspectRatio
to approximate the number of rectangles in each row and columntotalFreeSpace
to boundingBoxArea
gives you the desired density. If not, then an O(n^2)
algorithm should help calculate the density per the problem description (assuming total rectangle count isn't too large).Upvotes: 0