Code covered by the BSD License

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

### Dominik Hofer (view profile)

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;

% wavelength
% power in watts
% illuminated beam area
% beam diameter, used to calculate a circular area
% surface normal
% distance to base coordinate rigin along the surface normal to the global
% origin
% 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]
% translation of the object with respect to the global origin [dx dy dz]

% 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)));

% 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);

if ~isempty(obj.power) && ~isempty(obj.area)