function result=pw_farZoneCrit(d,N,Name,r0,theta_min,theta_max)
y=@(x)N^2*d*(1+cos(x));
theta=0:180;
theta=theta*pi/180;
grating_size=[-(d*N/2),(d*N/2)];
zone_X=[0,(r0).*cos((theta_min:(theta_max-theta_min)/100:theta_max).*pi/180),0];
zone_Y=[0,(r0).*sin((theta_min:(theta_max-theta_min)/100:theta_max).*pi/180),0];

fig = figure('visible', 'off');
plot(y(theta).*cos(theta),y(theta).*sin(theta),...
y(theta).*cos(theta)./5,y(theta).*sin(theta)./5,...
y(theta).*cos(theta)./20,y(theta).*sin(theta)./20,...
'LineWidth', 2);
    set(gca, 'FontSize', 18, 'LineWidth', 2);
xlabel('Z , mm');
ylabel('Y , mm');
title({'Far zone criterium in ZY plane';['d =' num2str(d) 'mm N = ' num2str(N)]});
legend('R far','R far/5','R Far/20');
print( fig , '-dpng', [Name '_ZY.png']);
close(fig);

fig = figure('visible', 'off');
plot(y(theta).*cos(theta)/20,y(theta).*sin(theta)/20,zone_X,zone_Y,grating_size,[0 0] ,'LineWidth', 2);
    set(gca, 'FontSize', 18, 'LineWidth', 2);
xlabel('Z , mm');
ylabel('Y , mm');
title({'Far zone criterium in ZY plane, ';['d =' num2str(d) 'mm N = ' num2str(N)]});
legend('Far zone criterium/20','Observation zone','Grating')
print( fig , '-dpng', [Name 'log_ZY.png']);
close(fig);


fig = figure('visible', 'off');
semilogy(theta*180/pi,y(theta),[theta(1) theta(end)]*180/pi,[r0 r0], 'LineWidth', 2);
    set(gca, 'FontSize', 18, 'LineWidth', 2);
xlabel('\theta , deg');
ylabel('Criterium , mm');
grid on;
legend('Far zone criterium','Observation zone');
%grid minor;
title({'Far zone criterium related to theta';['d =' num2str(d) 'mm N = ' num2str(N)]});
print( fig , '-dpng', [Name '_theta.png']);
close(fig);

end


