How to compute the ratio of the insection point in each grid on the boundary of a real structure
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Bruno Luong
2019 年 9 月 9 日
編集済み: Bruno Luong
2019 年 9 月 9 日
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 件のコメント
Bruno Luong
2019 年 9 月 16 日
編集済み: Bruno Luong
2019 年 9 月 16 日
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
その他の回答 (1 件)
darova
2019 年 9 月 11 日
'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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!