Saturday, September 10, 2022
HomeGame Developmentgeometry - Algorithm for "therapeutic" a number of rectangles right into a...

geometry – Algorithm for “therapeutic” a number of rectangles right into a smaller variety of rectangles?


First, we are able to convert your supply rectangles to cells in your underlying grid, to make the enter extra uniform. (Successfully rasterizing the issue)

This can allow us to discover optimizations that may not be apparent when working immediately with the supply rectangles – notably when it includes splitting a number of supply rectangles to recombine them in another way.

Example converting rectangles into grid cells and back

Subsequent we are able to discover related areas of the identical color, utilizing depth-first-search or flood filling algorithms. We are able to think about every related area (a polyomino) in isolation – nothing that we do to a distinct area must affect this one.

Successfully we wish to discover a strategy to dissect this polyomino into rectangles (sadly a lot of the literature I can discover is concerning the reverse drawback: dissecting rectangles into polyominoes! This makes it difficult to seek for leads…)

One easy methodology is to mix horizontal runs of adjoining squares into lengthy skinny rectangles. Then we are able to examine towards the row above and mix if our run begins & ends match up – both as we end every run/row, or as we think about every cell so as to add to the present run.

Decomposing a polyomino into horizontal runs, then merging vertically

I do not know but how shut this methodology will get to optimum. It appears it will possibly run right into a little bit of hassle when a row it hasn’t thought of but suggests a distinct cut up than the rows it is seen up to now:

Example of a case with a 3-rectangle solution, where the method above finds 4

Detecting when a run/rectangle is precisely coated by runs above & beneath, then splitting it and merging them will resolve this specific case, however I have never explored how common the issue is.

I’ve additionally checked out strategies the place we stroll the perimeter of the polyomino, and lower throughout anytime we encounter a concave nook, however this strategy seems extra error-prone to me. Getting optimum outcomes appears to require prioritizing cuts that be part of two concave corners, and shapes containing hollows want particular dealing with, so the row scan methodology appears to have the simplicity benefit.

Yet one more methodology I am taking a look at is to take the primary run discovered within the high row & lengthen it down so far as you possibly can. Then take the primary run within the high row of what is left… This will get tripped-up on inverted T shapes although, so it is not optimum both.

I really feel like there’s in all probability a manner to make use of dynamic programming to seek out the optimum cut up, however I have never discovered it but.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments