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?
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)))