3

I need a packing algorithm that fits a set of circles of varying radii, if the circles fit, in a rectangle. I've seen various pages on Wikipedia and other sites, but the implementation itself is either too complicated or simply a mathematical theorem, neither of which I have the experience or knowledge to utilize.

Someone asked this question, which is sort of the inverse--I need circles in rectangles not vice versa, and I would prefer Java, not MATLAB, though I suppose if necessary I could port it.

Thanks!

EDIT:

I don't need to find the smallest rectangle in which the circles would fit, I just need to know if the circles would fit within a given rectangle with specified dimensions.

Community
  • 1
  • 1
skeggse
  • 6,103
  • 11
  • 57
  • 81
  • You could use a genetic algorithm which are always pretty simple to write, it depends on your goal if this is the correct approach though. – austinbv Aug 10 '11 at 19:28
  • There's this: http://goo.gl/wrxXV, though I should say (and update the question) that I don't need to find the smallest rectangle or anything, I need to figure out _IF_ a given set of circles fit within a specified rectangle. – skeggse Aug 10 '11 at 19:35

2 Answers2

2

This problem is appears heavily related to bin packing and so I suspect it is NP-hard. So unfortunately I don't think there's a good algorithm for solving this efficiently (aka non-brute force).

I don't even think there's a good, simple, greedy way of approaching it.

There have been many research papers written on the subject though if you have access to them. Here is one: http://www.sciencedirect.com/science/article/pii/S0377221707004274

tskuzzy
  • 35,812
  • 14
  • 73
  • 140
2

Google: algorithm, pack circles in rectangle http://www.jstor.org/stable/4102107 Shows up right underneath this stack overflow question. The jstor.org paper spells out a greedy circles in rectangle packing algorithm.

Louis Ricci
  • 20,804
  • 5
  • 48
  • 62