How to pack circles of different sizes in a rectangle?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sunstar
el 12 de Dic. de 2013
Comentada: Sunstar
el 12 de Dic. de 2013
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!
0 comentarios
Respuesta aceptada
Image Analyst
el 12 de Dic. de 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 comentarios
Image Analyst
el 12 de Dic. de 2013
Editada: Image Analyst
el 12 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!