How to pack circles of different sizes in a rectangle?

6 views (last 30 days)
I am curious to see how I can pack circles with different sizes in a rectangle. The desired filling fraction is an input and circles cannot overlap. Any hint?
Thanks in advance!

Accepted Answer

Image Analyst
Image Analyst on 12 Dec 2013
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. That, combined with the rand() function to get center locations and radii, will allow you to do this.
Using rand you can randomly place or reject new circles in a Monte Carlo fashion. If you want to fill the rectangle more systematically and completely , you'll have to use the Euclidean Distance Transform to figure out the size of the largest circle than can be placed and where the largest circle can be placed. Keep going until the circles become smaller than what you care about.
  3 Comments
Image Analyst
Image Analyst on 12 Dec 2013
Edited: Image Analyst on 12 Dec 2013
Keep track of all centers and radii. Compare the tentative new circle against past circles. If the distance between the centers is more than the sum of the two radii, then they don't overlap and you're okay to accept it.
if sqrt((x2-x1)^2+(y2-y1)^2) > (r1+r2)
% Then it's acceptable.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!