Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a requirement where i have to draw areas on HTML5 canvas, area are drawn using circle,rectangle,polygon tool(This is part of configuration i.e only defining the area's). Later in Dashboard(where the configured area's can be viewed) i want to show small sub area's within the area(dynamically through code), the number of sub area's will not be fixed(but the size of sub area's is fixed assume 20 X 20). I want this sub area's to be plotted in such a way that they fit the best possible in their area's and does not come out of area.Can anyone please tell me the most efficient way of doing this. Refer to this image.
Posted

1 solution

When all boiled down, it seems that your question relates to the Packing Problem class of problems (http://en.wikipedia.org/wiki/Packing_problem[^])

A question on SO that seems almost identical to yours may be found here: http://stackoverflow.com/questions/3516044/fill-arbitrary-2d-shape-with-given-set-of-rectangles[^]

The accepted answer to that question makes reference to a research paper from 1982 by András Hegedüs, called Algorithms for covering polygons by rectangles - link[^] (which costs $35 or requires appropriate institute access) and makes the suggestion to search for papers that cite it.

There are almost certainly open-source implementations of the algorithm it describes. With some time and the right search-terms, you'll hopefully be able to find something useful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900