algorithm - Filling a polygon with rectangles -
I have a smooth polygon, say that oval and polygons are transformed into straight lines with belges. I want to fill this polygon with as many rectangles as possible, but the rectangle can be of any size and any amount to maintain accuracy in the small corners in the polygon.
The reason for this is testing a hit on a web page on the polygon, the only practical way is to fill it with divs and test the hits on all the divs.
Of course, there will be a minimum square size for any rectangle, not so that we just guess the polygon and again with rectangle of pixel size.
In the general case, if you have a digital shape with rectangle exactly Represents, you will need at least the rectangle, because the pixels on the corners of the outline are made if you think of a digital straight edge at 45 degrees, it means a rectangle per pixel. This is a serious limitation (and can not even think of non-digital shapes.) That said, you guess the figure with a certain error, and I suggest you first To make the size smaller by a constant factor for you: You will overlay a grid on the shape, it will decide if every tile is related to the shape or not. By doing this, you change your shape to a binary image with "big pixels", and the challenge is to break this image into rectangles (at the right time). I suggest a simple greedy strategy that you try to find a larger rectangle that fits perfectly, and then repeat with that part. If you apply an operation with a large and large rectangular structure element, you will find the largest rectangle that fits in size image theory, trying all the combinations of width and height. Should and should keep the largest area or perimeter; It is a huge amount of work, I advise to try with increasing classes first, and when you get the largest section to continue in the direction which allows it. After you find a large rectangle, erase it from the image of the size and start it again, as long as you do not wipe it out completely.
Comments
Post a Comment