Code covered by the BSD License  

Highlights from
Huygens-Fresnel integral approximation, free-form apertures and rough surfaces

image thumbnail

Huygens-Fresnel integral approximation, free-form apertures and rough surfaces

by

 

Simulate wave propagation through free-form apertures, or off rough surfaces.

plotSetup(varargin)
function h = plotSetup(varargin)
% plotSetup - show the relations of various objects
%
% varargin ... list of cell arrays
%              object: 'source' or 'surface' object
%              scaling factor: scale coordinate system unit vectors
%              nGrid: number of points for surface interpolation
%
% cell array for a surface object:
% {object, scaling factor, nGrid}, e.g. {surface, .01, [32 3]}
%
% cell array for a light source:
% {source object, scaling factor}, e.g. {lightsource, .01}
%
% example call:
% plotSetup({lens1, .01, [128 128]}, {surface, .01, [32 3]}, {lightsource, .01})

h = figure;
hold on;

for k = 1:nargin
	if isstruct(varargin{k}{1}) && isfield(varargin{k}{1}, 'type')
		if strcmp(varargin{k}{1}.type, 'source') || strcmp(varargin{k}{1}.type, 'surface')		
			% origin
			x = varargin{k}{1}.translations([1 1 1]).';
			y = varargin{k}{1}.translations([2 2 2]).';
			z = varargin{k}{1}.translations([3 3 3]).';
			
			% scaling factor
			if numel(varargin{k}) >= 2 && isnumeric(varargin{k}{2}) && numel(varargin{k}{2}) == 1
				s = varargin{k}{2};
			else
				s=[];
			end	
			
			% coordinate system
			u = s .* varargin{k}{1}.coordinateSystem(1,:);
			v = s .* varargin{k}{1}.coordinateSystem(2,:);
			w = s .* varargin{k}{1}.coordinateSystem(3,:);
			
			% quiver plot
			quiver3(x,y,z,u,v,w);
			
			if isfield(varargin{k}{1}, 'grid')
				% get grid and interpolate data
				if numel(varargin{k}) >= 3 && isnumeric(varargin{k}{2}) && numel(varargin{k}{2}) == 2
					nGrid = varargin{k}{2};
				else
					nGrid=[];
				end				
				[X, Y, Z, E] = interpolateGrid(varargin{k}{1}, 'grid', nGrid);
			
				if isfield(varargin{k}{1}, 'saturation') && ~isempty(varargin{k}{1}.saturation)
					surf(X, Y, Z, varargin{k}{1}.saturation(E.*conj(E)));
				else
					surf(X, Y, Z, E.*conj(E));
				end
				xlabel('x');
				ylabel('y');
				zlabel('z');
				colorbar;
				shading flat;
			end
		else
			disp('unknown type');
		end
	else
		disp('no type field');
	end
end

Contact us