What's the algorithm to divide a rectangle (c struct
with 4 int
s) to a random number of smaller rectangles (return a list of struct
s)? Even better if the max and min dimension of the smaller rectangles can be controlled by a parameter.
e.g.
+----------+ +-------+--+
| | | | |
| | | | |
| | --> |---+---+--| (good)
| | | | |
| | +---+ |
| | | | |
+----------+ +---+------+
smaller shapes should be 4-sided, the following is not good:
+----------+ +-------+--+
| | | | |
| | | | |
| | --> |---+---+--| (not good)
| | | |
| | +---+ |
| | | | |
+----------+ +---+------+
Thanks!
Appendix: (rectangle for Moron's discussion)
+----+--------+
| | |
| +---+----+
| | | | (rectangle-chase)
+----+---+ |
| | |
+--------+----+
We could divide our rectangle into two equal parts, or halves. Then, we can halve each half again until we have four equal parts. If we take two-halves and halve them again, we get quarters. So, this is the rectangle that is divided into quarters.
Let's say the rectangle measures 10 by 3 inches. Draw four lines perpendicular to the long dimension at two-inch increments. You will end up with five equal rectangles which measure two by three inches. Done!
For example: A rectangle with a width of 360m and a height of 592m cannot be divided into equal squares. A rectangle with a width of 100m and height of 300m can be divided into squares with sides 10m. 10 across and 30 down.
Note: In order to solve this type of question the key is to understand the meaning of dividing the rectangle into 6 equal parts. It is important to divide it only w.r.t its length of its breadth. If we divide it w.r.t to the length and breadth at once, we obtain 36 equal rectangles.
Split the rectangle into two. Recurse.
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