How plot a grid of rectangles on an overlaid circle?

How to plot a circle of radius R and an overlaid grid of rectangles (with each rectangle of dimensions LxW)?
Choice of dimensions are so that the rectangular grid is larger than the dimeter of the circle and the centre of the circle is on one of the rectangle corners within the grid. The circle fully sits within the rectangular grid.
Secondly, from the plot or otherwise can Matlab help count the full rectangles within the circle?

 Accepted Answer

R = 5; % circle radius
H = 1; % rect height
W = 2; % rect width
circ=nsidedpoly(1000,"Radius",R); %polyshape for the circle
Grid=scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[W,H]);
Grid=arrayfun(@(i)translate(Grid,H*[0,i]),-ceil(R/H):ceil(R/H)-1)';
Grid=arrayfun(@(i)translate(Grid,W*[i,0]),-ceil(R/W):ceil(R/W)-1,'uni',0);
Grid=vertcat(Grid{:}); %polyshape vector for grid rectangles
numContained=sum( area(intersect(Grid,circ))>=area(Grid(1))*0.9999 ) %count contained rectangles
numContained = 28
plot([circ; Grid],'FaceColor','w'); axis equal

13 Comments

JM
JM on 20 May 2024
Edited: JM on 20 May 2024
@Matt J, Thanks. The number of full rectangles does not seem to come close to the standard formula (scroll down for formula) for large circle and large number of rectangles. For die width = 5mm, die deight =2.25mm and wafer size = 8 inch (203.2mm) and rest all set to zero, value is 2654 while yourr script gives 10900 as the total number of full rectangles. Am I missing something?
Likely you are plugging in the diameter instead of the radius. The calculation below is in pretty close agreement. Also, I'm assuming your "standard formula" is an approximation. For one thing, the formula appears to assume square die, and gives non-integer results. In any case, the value of 2654 cannot be precise because the number of contained rectangles must be a multiple of 4.
R = 200/2; % circle radius
H = 5; % rect height
W = 2.25; % rect width
circ=nsidedpoly(1000,"Radius",R); %polyshape for the circle
Grid=scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[W,H]);
Grid=arrayfun(@(i)translate(Grid,H*[0,i]),-ceil(R/H):ceil(R/H)-1)';
Grid=arrayfun(@(i)translate(Grid,W*[i,0]),-ceil(R/W):ceil(R/W)-1,'uni',0);
Grid=vertcat(Grid{:}); %polyshape vector for grid rectangles
numContained=sum( area(intersect(Grid,circ))>=area(Grid(1))*0.9999 ) %count contained rectangles
numContained = 2652
@Matt J Thanks, I must have been too tired last night to notice my mistake. Indeed I was plugging in the diameter. All working as expected now and giving me correct numbers out.
I have adapted your code and added a few things which are needed. Next I would like to color the 2 bottom right rectangles within each larger "black" rectangles differently and finally count how many such full differently colored retangle pairs remain inside the inner circle. This completes my requirement.
(If counting the differently colored full rectangle pairs is not possible computationally, I am happy to count them visually)
clear; clc;
wDia = 152400; % waferDia [um]
EdgeExcl = 10000 ; % edge exclusion [um]
wR = wDia/2;
waferRadiusEdgeExluded = wR - EdgeExcl;
R = waferRadiusEdgeExluded;
H = 2250; % die height [um]
W = 5000; % die width [um]
rH = 13500; % reticle height [um]
rW = 15000; % reticle height [um]
circ = nsidedpoly(1000,"Radius",R); %polyshape for the circle
wfr = nsidedpoly(1000,"Radius",wR); %polyshape for wafer
Grid = scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[W,H]);
Grid = arrayfun(@(i)translate(Grid,H*[0,i]),-ceil(R/H):ceil(R/H)-1)';
Grid = arrayfun(@(i)translate(Grid,W*[i,0]),-ceil(R/W):ceil(R/W)-1,'uni',0);
Grid = vertcat(Grid{:}); %polyshape vector for grid rectangles
dieContained=sum( area(intersect(Grid,circ))>=area(Grid(1))*0.9999 ); disp ("Gross die/Wfr"); disp (dieContained);
Gross die/Wfr 1148
% plot die grid on uable wafer
dp = plot([circ; Grid],'FaceColor','m', 'EdgeColor', 'w'); axis equal; hold on; % plot usable wafer
%%% plot reticle grid on full wafer
rGrid = scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[rW,rH]);
rGrid = arrayfun(@(i)translate(rGrid,rH*[0,i]),-ceil(wR/(rH)):ceil(wR/(rH))-1)';
rGrid = arrayfun(@(i)translate(rGrid,rW*[i,0]),-ceil(wR/(rW)):ceil(wR/(rW))-1,'uni',0);
rGrid = vertcat(rGrid{:}); %polyshape vector for grid rectangles
wp = plot([wfr; rGrid],'FaceColor','none'); axis equal; %plot full wafer
rContained=sum( area(intersect(rGrid,circ))>=area(rGrid(1))*0.9999 ); disp ("Gross ReticleShot/Wfr"); disp (rContained);
Gross ReticleShot/Wfr 52
I don't know what "2 bottom right rectangles" would mean. The bottom right rectangle has 3 neighbors.
JM
JM on 21 May 2024
Edited: JM on 21 May 2024
@Matt J, Within each big rectangle (in black), there are 18 small rectangles (white border). The bottom two rectangles on the right within each big rectangle needs different coloring (keepnig white border in between).
I have mannually colored 6 rectangles (as example) in the attached image. I also need a count of the full differently colored retangle pairs which are inside the inner circle.
clear; clc;
wDia = 152400; % waferDia [um]
EdgeExcl = 10000 ; % edge exclusion [um]
wR = wDia/2;
waferRadiusEdgeExluded = wR - EdgeExcl;
R = waferRadiusEdgeExluded;
H = 2250; % die height [um]
W = 5000; % die width [um]
rH = 13500; % reticle height [um]
rW = 15000; % reticle height [um]
tH=round(rH/H);
tW=round(rW/W);
%%Form the bounding circles as polyshapes
innerCirc = nsidedpoly(1000,"Radius",R); %polyshape for the circle
outerCirc = nsidedpoly(1000,"Radius",wR); %polyshape for wafer
%%%Form individual cells as polyshapes
smallCell= scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[W,H]);
largeCell=scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[rW,rH]);
subgrid=tileShapes(smallCell,[W,H],[0,tW-1,0,tH-1]); %6x3 tiling of one large cell
cornerCell=union(subgrid([12,18]));
%%%Tile the cells
coarseTiles=tileShapes(largeCell,[rW,rH], getLimits(wR,[rW,rH]));
fineTiles=tileShapes(subgrid,[rW,rH], getLimits(R,[rW,rH]));
cornerTiles=tileShapes(cornerCell,[rW,rH],getLimits(R,[rW,rH]) );
%%%Plot the elements
plot([outerCirc;coarseTiles(:)],'FaceColor','none'); axis equal;hold on
plot([innerCirc; fineTiles(:)],'FaceColor','m', 'EdgeColor', 'w');
plot(cornerTiles,'FaceColor','g'); hold off
%%%Compute containment
dieContained=numInCircle(innerCirc,fineTiles); disp ("Gross die/Wfr"); disp (dieContained);
Gross die/Wfr 1148
rContained=numInCircle(innerCirc,coarseTiles); disp ("Gross ReticleShot/Wfr"); disp (rContained);
Gross ReticleShot/Wfr 52
cornersContained=numInCircle(innerCirc,cornerTiles)
cornersContained = 59
function lims=getLimits(R,xy)
L=ceil(R./xy);
lims=[-L(1),+L(1)-1, -L(2),+L(2)-1];
end
function N=numInCircle(circ,tiles)
V=vertcat(tiles.Vertices);
N=sum( all( reshape(isinterior(circ, V),4,[]) ,1));
end
function Tiles=tileShapes(p,stride,lims)
arguments
p; stride (1,2); lims (1,4) {mustBeInteger}
end
W=stride(1);
H=stride(2);
lims=num2cell(lims);
[Xmin,Xmax,Ymin,Ymax]=deal(lims{:});
Tiles=p;
Tiles = arrayfun(@(i)translate(Tiles,W*[i,0]),Xmin:Xmax,'uni',0);
Tiles=horzcat(Tiles{:});
Tiles = arrayfun(@(i)translate(Tiles,H*[0,i]),(Ymax:-1:Ymin)','uni',0);
Tiles = vertcat(Tiles{:});
end
JM
JM on 22 May 2024
Edited: JM on 22 May 2024
@Matt J. The tileShapes function appears to have a typo. This needs to be commented, I think, as below.
%arguments p; stride (1,2); lims (1,4) {mustBeInteger}
JM
JM on 22 May 2024
Edited: JM on 22 May 2024
@Matt J. Thanks, If I understand correctly, the containment calculation considers the bottom right corner small rectangles (BRCSRs) as pairs in a Tile. I also need the counting of the single BRCSR (single rectangles) which remain within the inner circle. In the picture below, within the white transparent white inner block we have 52 BRCSR pairs (not shown). Then there are the yellow ones above it (shown, total 7). So the line below correcly gives as (52+7=) 59 as the total BRCSR pairs contained within the inner circle
cornersContained=numInCircle(innerCirc,cornerTiles)
I need to count the single green BRCSR's as well, which remain inside the inner circle. I expect answer of 52*2 + 7*2 + 5 = 123.
How to have the BRCSR's as single rectangles (not pairs which is OK in the plot) and then count contanment within the inner circle?
@Matt J. This is how I changed the body of your code to count BRCSR as single rectangles. Please see if this is fine or could be better
tH=round(rH/H);
tW=round(rW/W);
%%Form the bounding circles as polyshapes
innerCirc = nsidedpoly(1000,"Radius",R); %polyshape for the circle
outerCirc = nsidedpoly(1000,"Radius",wR); %polyshape for wafer
%%%Form individual cells as polyshapes
smallCell= scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[W,H]);
largeCell=scale(nsidedpoly(4,'Side',1,'Center',[+1,+1]/2),[rW,rH]);
subgrid=tileShapes(smallCell,[W,H],[0,tW-1,0,tH-1]); %6x3 tiling of one large cell
cornerCell_1 = subgrid(12);
cornerCell_2 = subgrid(18);
%%%Tile the cells
coarseTiles=tileShapes(largeCell,[rW,rH], getLimits(wR,[rW,rH]));
fineTiles=tileShapes(subgrid,[rW,rH], getLimits(R,[rW,rH]));
cornerTiles_1=tileShapes(cornerCell_1,[rW,rH],getLimits(R,[rW,rH]));
cornerTiles_2=tileShapes(cornerCell_2,[rW,rH],getLimits(R,[rW,rH]));
%%%Plot the elements
plot([innerCirc; fineTiles(:)],'FaceColor','m', 'EdgeColor', 'w'); axis equal;hold on
plot([outerCirc;coarseTiles(:)],'FaceColor','none', 'EdgeColor', 'b');
plot(cornerTiles_1,'FaceColor','g');
plot(cornerTiles_2,'FaceColor','c'); hold off;
%%%Compute containment
dieContained=numInCircle(innerCirc,fineTiles); disp ("Gross die/Wfr"); disp (dieContained);
rContained=numInCircle(innerCirc,coarseTiles); disp ("Gross ReticleShot/Wfr"); disp (rContained);
cornersContained_1=numInCircle(innerCirc,cornerTiles_1); disp (cornersContained_1);
cornersContained_2=numInCircle(innerCirc,cornerTiles_2); disp (cornersContained_2);
The sum of the last two outputs is 123 which is what I expect.
The tileShapes function appears to have a typo. This needs to be commented, I think, as below.
No, your Matlab version is just really old. You should upgrade if you can!
JM
JM on 22 May 2024
Edited: JM on 22 May 2024
Upgrade, as much as I would want it, is beyond my control I am afraid
JM
JM on 22 May 2024
Moved: Matt J on 28 May 2024
@Matt J. Thanks

Sign in to comment.

More Answers (1)

R = 5; % circle radius
L = 1; % horizontal grid spacing
W = 2; % vertical grid spacing
C = [7 8]; % center of the circle
% calculate some points on the circle
th = linspace(0,2*pi,100);
xc = C(1)+R*cos(th);
yc = C(2)+R*sin(th);
% calculate the grid's x and y coordinates
xg = C(1)+W*(floor(-R/W):ceil(R/W));
yg = C(2)+L*(floor(-R/L):ceil(R/L));
% plot the circle
plot(xc,yc)
axis equal
% create the vertical grid lines
nx = numel(xg);
xdata = [xg;xg;NaN(1,nx)];
ydata = [repmat(yg([1 end]).',1,nx); NaN(1,nx)];
line(xdata,ydata,'Color','k')
% create the horizontal grid lines
ny = numel(yg);
ydata = [yg;yg;NaN(1,ny)];
xdata = [repmat(xg([1 end]).',1,ny); NaN(1,ny)];
line(xdata,ydata,'Color','k')
% count the rectangles completely inside the circle
n_rectangles_inside = nnz(conv2((xg-C(1)).^2+(yg.'-C(2)).^2 <= R^2,ones(2)) == 4)
n_rectangles_inside = 28

Categories

Products

Release

R2018a

Asked:

JM
on 20 May 2024

Moved:

on 28 May 2024

Community Treasure Hunt

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

Start Hunting!