How to compute the ratio of the insection point in each grid on the boundary of a real structure
2 views (last 30 days)
Show older comments
In the Cartesian grid, the real structures are pixelized into the staircase approximation. To reduce the staircase error, the effective permittivity is computed, which is weighted by the fraction of the mesh step inside the material 1 or 2 (See the below figure). For instance, the structure is sphere. How I can compute the fraction ratio of four edges in each grid on the boundary of the sphere? Could you please give me some suggestions?
% build Cartesian grid
[Y1,X1]=meshgrid(y_1grid,x_1grid);
% build structure (sphere)
UCC= ((X1+dx/2).^2 + (Y1+dy/2).^2) <= (diam/2.0)^2;
eps_cc=eps(2)*(UCC==1)+eps(1)*(UCC==0);
% find the boundary
[Fx,Fy]=gradient(eps_cc);
boundary=(Fx~=0)|(Fy~=0);
% compute the ratio of intersection point
??
Big Thanks to you
2 Comments
Accepted Answer
Bruno Luong
on 9 Sep 2019
Edited: Bruno Luong
on 9 Sep 2019
Assuming the boundary has one connexed piece
x=-3:12;
y=-3:10;
[X,Y]=meshgrid(x,y);
cx = 4;
cy = 3;
r = 5;
Z = (X-cx).^2 + (Y-cy).^2 - r^2;
C = contourc(x,y,Z,[0 0]);
Cx = C(1,2:end);
Cy = C(2,2:end);
[Cx; Cy] % fractional crossing is grouped here
close all
hold on
plot(X,Y,'-b');
plot(X',Y','-b');
plot(Cx,Cy,'-r');
plot(cx,cy,'ko');
axis equal
2 Comments
Bruno Luong
on 16 Sep 2019
Edited: Bruno Luong
on 16 Sep 2019
The pixels coordinates are
ii=interp1(x,1:length(x),Cx,'previous')
jj=interp1(y,1:length(y),Cy,'previous')
And the corresponding fractional are
ratio_x=interp1(x,1:length(x),Cx)-ii
ratio_y=interp1(y,1:length(y),Cy)-jj
Just loop on the list [ii; jj; ratio_x; ratio_y] and do whatever you need to do.
for pixel = [ii; jj; ratio_x; ratio_y]
i = pixel(1);
j = pixel(2);
rx = pixel(3);
ry = pixel(4):
% do something with i,j,rx,ry ...
end
Alternatively, to avoid using INTERP1 you can call contour with pixel coordinates
C = contourc(1:size(Z,2),1:size(Z,1),Z,[0 0]);
Cx = C(1,2:end);
Cy = C(2,2:end);
% these replace the INTERP1 stuffs
ii = floor(Cx);
jj = floor(Cy);
ratio_x = Cx-ii;
ratio_y = Cy-jj;
The process ii,jj,ratio_x,ratio_y
More Answers (1)
darova
on 11 Sep 2019
'That's why I try to subgrid the current one pixel into 10 smaller grids and determine whether each point is inside the circel or not.'
THAT IS GREAT IDEA
See attached script
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!