7
votes

I have a kind of cutting problem. There is an irregular polygon that doesn't have any holes and a list of standard sized of rectangular tiles and their values.

I want an efficient algorithm to find the single best valued tile that fit in this polygon; or an algorithm that just says if a single tile can fit inside the polygon. And it should run in deterministic time for irregular polygons with less than 100 vertices.

Please consider that you can rotate the polygon and tiles. Answers/hints for both convex and non-convex polygons are appreciated.

3
A Google search on [rectangle inside polygon] returns some interesting results, including this research paper: mpi-inf.mpg.de/~jeschmid/public/Knauer2012.pdf, and a few SO questions: stackoverflow.com/q/610462/56778, and stackoverflow.com/q/10214829/56778Jim Mischel
You mentioned your polygons are irregular. Are they convex?phs
Of course I had Googled it before. But thanks for your guidance. And I edited the problem.Zhr Saghaie
Here's a simple approximation idea that I would try for a convex polygon. First rotate it until it's as horizontal as possible (look for a diameter and make it horizontal). Given a tile, rotate that too, if necessary, to make it horizontal. Then place it in the center of the polygon's bounding rectangle, and see which vertices are inside the polygon. If only one or two adjacent vertices are outside, move the tile in the obvious direction and see if you can get them all inside.Hew Wolff
Can you describe why @JimMischel's links don't suffice?mbeckish

3 Answers

7
votes

Disclaimer: I've never read any literature on this, so there might be a better way of doing this. This solution is just what I've thought about after having read your question.

A rectangle has two important measurements - it's height and it's width

now if we start with a polygon and a rectangle:

polygon and rectangle

1: go around the perimeter of the polygon and take note of all the places the height of the rectangle will fit in the polygon (you can store this as a polygon*):

where will the hight fit?

2: go around the perimeter of the new polygon you just made and take note of all the places the width of the rectangle will fit in the polygon (again, you can store this as a polygon):

where will the width fit?

3: the rectangle should fit within this new polygon (just be careful that you position the rectangle inside the polygon correctly, as this is a polygon - not a rectangle. If you align the top left node of the rectangle with the top left node of this new polygon, you should be ok)

4: if no area can be found that the rectangle will fit in, rotate the polygon by a couple of degrees, and try again.

*Note: in some polygons, you will get more than one place a rectangle can be fitted:

more than one rectangle can be fitted here

2
votes

After many hopeless searches, I think there isn't any specific algorithm for this problem. Until, I found this old paper about polygon containment problem.
That mentioned article, present a really good algorithm to consider if a polygon with n points can fit a polygon with m points or not.
The algorithm is of O(n^3 m^3(n+m)log(n+m)) in general for two transportable and rotatable 2D polygon.

I hope it can help you, if you are searching for such an irregular algorithm in computational geometry.

2
votes