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.

createSource.m
function obj = createSource(varargin)
% createSource - create a light source type structure

p = inputParser;
p.addParamValue('type','source',@ischar);
p.addParamValue('subtype', '', @ischar);
p.addParamValue('name', '', @ischar);
p.addParamValue('fileName', '', @ischar);
p.addParamValue('folder', 'objects', @ischar);

% wavelength
p.addParamValue('wavelength', 632.8e-9, @isnumeric);
% power in watts
p.addParamValue('power', 1e-3, @isnumeric);
% irradiance W/m
p.addParamValue('irradiance', [], @isnumeric);
% illuminated beam area
p.addParamValue('area', [], @isnumeric);
% beam diameter, used to calculate a circular area
p.addParamValue('diameter', [], @isnumeric);
% surface normal
p.addParamValue('normal',[], @isnumeric);
% distance to base coordinate rigin along the surface normal to the global
% origin
p.addParamValue('normalDistance', [], @isnumeric);
% rotated coordinate system, columnwise unit vectors: [xx yx zx; xy yy zy; xz yz zz]
p.addParamValue('coordinateSystem', [], @(x)isnumeric(x) && size(x,1)==3 && size(x,2) == 3);
% rotations of aperture with respect to the origin [alpha beta gamma]
p.addParamValue('rotations', [], @isnumeric);
% translation of the object with respect to the global origin [dx dy dz]
p.addParamValue('translations', [], @isnumeric);

% ligth intensity function in the objects own x/y plane
% 2d Gaussian beam:
%	@(x,y,A,sx,sy,x0,y0) A.*exp(-((x-x0).^2./(2.*sx.^2)+(y-y0).^2./(2.*sy.^2)));
% 2d Gaussian beam with additional rotation 'th':
%	@(x,y,A,sx,sy,x0,y0,th)
%	A.*exp(-((cos(th).^2./(2.*sx^2)+sin(th).^2./(2.*sy.^2)).*(x-x0).^2+2.*(-sin(2.*th)./(4.*sx^2)+sin(2.*th)./(4.*sy.^2)).*(x-x0).*(y-y0)+((sin(th).^2./(2.*sx^2)+cos(th).^2./(2.*sy.^2)).*(y-y0).^2)));
p.addParamValue('function', @(x,y,r,P) P(1).*exp(-((x-P(2)).^2./(2.*P(3).^2)+(y-P(4)).^2./(2.*P(5).^2))), @(x)isa(x,'function_handle'));

% paramters of the function;
% here [max. amplitude, x-offset, x-standard deviation, y-offset, y-standard deviation]
p.addParamValue('parameters', [1 0 0.001 0 0.001], @isnumeric);	


%% parse the results, calculate missing parameters, return object
p.parse(varargin{:});
obj=p.Results;

displayMessage(1, 'Start create source');

% check basic inputs like the surface normal, the normal distance, 
% translations and rotations
obj = checkBasics(obj);

% compute irradiance
if isempty(obj.irradiance)
	if ~isempty(obj.power) && ~isempty(obj.area)
		obj.irradiance = obj.power / obj.area;
	elseif ~isempty(obj.power) && ~isempty(obj.diameter)
		obj.irradiance = obj.power / (obj.diameter^2 * pi/4);
	else
		displayMessage(-1, [obj.name ': ERROR missing parameters ''power'' or ''diameter''']);
	end
end

displayMessage(1, 'DONE create source');

Contact us