Asked by Kian Babanezhad
on 17 May 2018 at 17:45

Suppose we have circles with 4 different diameter (A:0.1, B:0.2, C=0.3, D=0.4), We want to arrange them in a square (5*5) to reach the maximum area. How many of each circle put in the square? a.A + b.B + c.C + d.D = 25 , actually we want to detect a, b, c ,d and position of them. How can I do it in MATLAB?

Answer by KSSV
on 18 May 2018 at 3:08

R = 0.1; % RAdius of circle S = 5 ; % side of square % Square coordinates xs = [0 5 5 0 0] ; ys = [0 0 5 5 0] ; % Circle coordinates th = linspace(0,2*pi) ; xc = R*cos(th) ; yc = R*sin(th) ; % form centers of circle inside the square x = R:2*R:S-R ; y = R:2*R:S-R ;

[X,Y] = meshgrid(x,y) ; % plot figure hold on plot(xs,ys,'r') ; plot(X,Y,'.b') % for i = 1:size(X,1) for j = 1:size(X,2) plot(X(i,j)+xc,Y(i,j)+yc,'b') end end title(sprintf('Number of circles = %d',numel(X)))

Kian Babanezhad
on 18 May 2018 at 12:20

this code use just one kind of circles, radius of them is 0.1.

Torsten
on 18 May 2018 at 12:51

Seems to me that this is a field of ongoing research:

https://en.wikipedia.org/wiki/Circle_packing

If you find a solution, submit a publication.

Best wishes

Torsten.

KSSV
on 18 May 2018 at 13:20

You said how many of each circle...so took a single circle...

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Jan (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/401280-distribute-different-size-circles-inside-a-square#comment_569274

What exactly does "reach the maximum area" mean? What is e.g. "a.A"?

## Kian Babanezhad (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/401280-distribute-different-size-circles-inside-a-square#comment_569321

we want to cover maximum area inside the square with 4 different circle (rA=0.1, rB=0.2, rC=0.3 and rD=0.4). How many of each kind of circles we need to reach maximum area by these circles? for example we can cover X=24.404 (<25) by 1400 number of A, 400 number of B, 40 number of C and 15 number of D. we want to reach maximum of X. clear?

## Stephen Cobeldick (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/401280-distribute-different-size-circles-inside-a-square#comment_569385

@Kian Babanezhad: there is no general solution to this problem. Just because the task is simple does not mean that there is a tractable solution. Read more here:

https://www.mathworks.com/matlabcentral/answers/390517-rectangle-filled-with-equal-circles

https://www.mathworks.com/matlabcentral/answers/389947-how-can-i-packed-equal-circles-with-raduis-r-inside-a-rectangle-l-x-w

Sign in to comment.