Just like the title says, I need to break a rectangle into randomly shaped polygons.
Example, with 7 polygons:
+--------+--------+
|\ | 2 |
| \ 1 |''--..__|
| ------| 5 |
| 3 / \________|
| / /\ 6 |
|__/ 4 / \______|
| / 7 |
+-----+-----------+
I don't know if there's an algorithm already out there for this, but I can't seem to get my head around this.
I don't particularly care what language you answer in, but I'll be implementing in Java/Swing.
You may drop a bunch of random points on the rectangle, and calculate the Voronoi Diagram.
Here is a Java/Swing implementation.
I did some samples (but using Mathematica, not the above implementation)
HTH!
I'd draw a bunch of random lines across the full rectangle and then "split" the lines at each line intersection, so that you basically have some kind of net of lines. Then remove as many random line segments as you like until you reach the desired number of polygons.
Edit: So for your sample it would have been like this after adding the lines:
+----+---+----+---+
|\'--.\_/| / |
| \ X |''/-..__|
|--\--+-\+-/------|
|___\/___\/_______|
| /\ /\ |
|__/__\_/|_\______|
| / X | \ |
++----+-++---+----+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With