How can I find/plot mesh grid points outside an arbitrary contour?

5 Ansichten (letzte 30 Tage)
ttopal
ttopal am 21 Nov. 2018
Bearbeitet: ttopal am 22 Nov. 2018
Hi,
I am trying to calculate Green's function using a boundary and a mesh grid with this code:
N=128
theta=2*pi*(0:N-1)/N;
ka = 1.8411;
%create circle as an example
x=cos(theta); y=sin(theta);
dx=-sin(theta); dy=cos(theta);
ll=sqrt(dx.^2+dy.^2);
% get the normal to the contour
nx=dy./ll; ny=-dx./ll;
s2= 100;
grid_x=linspace(-1.5,1.5,s2);
grid_y=linspace(-1.5,1.5,s2);
E2_=zeros(s2,s2);
for m=1:s2
for k=1:s2
R = sqrt( (grid_x(m)-x).^ 2 + (grid_y(k)-y).^ 2) ;
dH2 = -ka * besselh(1,ka*R) .* ((grid_x(m)-x).*nx + (grid_y(k)-y).*ny );
u2_ = 1i/4*dH2;
E2_(m,k) = abs(trapz(theta,u2_));
% clear outside the boundary
[in,on]=inpolygon(grid_x(m),grid_y(k),x,y);
if ~in
E2_(m,k)=0;
end
end
end
figure
contourf(grid_x,grid_y,E2_);
colormap jet;
set(gcf,'color','w');
axis equal tight
xlabel('X')
ylabel('Y')
colorbar;
hold on
plot(x,y,'-w','linewidth',2)
Without checking where the grid point is, i have this result:
For grid size 100x100 points, if I use inpolygon function and clear outside it gives me:
close to the boundary the graph is not looking nice. If i increase the grid density say 500x500 points i have a reasonable plot:
Since I am interested only in plotting the result nicely, is there another way to manage this?
Also is it possible to use meshgrid and get rid of loops, as it becomes too slow for fine density grid.
Thank you

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by