Skip to content
Snippets Groups Projects
Commit 07ea1166 authored by Achilles Kappis's avatar Achilles Kappis
Browse files

Combine offset input arguments to a single translation vector and change...

Combine offset input arguments to a single translation vector and change variable name for the rotation/orientation of the geometries
parent a966eca0
No related branches found
No related tags found
1 merge request!5Update geometry generation functions
......@@ -3,7 +3,7 @@
% Author: Achilles Kappis
% e-mail: axilleaz@protonmail.com
%
% Date: 18/09/2024 (DD/MM/YYYY)
% Date: 20/09/2024 (DD/MM/YYYY)
%
% Copyright: MIT
% --------------------------------------------------
......@@ -43,16 +43,15 @@
% geometry the argument is ignored.
% [Default: 10 * ones(3, 1)].
%
% xOff [numeric] (Optional): X-axis offset. [Default: 0].
% trans [numeric] (Optional): This is a real vector with three elements,
% representing the translation of the geometry
% along the Cartesian axes.
% [Default: zeros(3, 1)].
%
% yOff [numeric] (Optional): Y-axis offset. [Default: 0].
%
% zOff [numeric] (Optional): Z-axis offset. [Default: 0].
%
% orient [numeric] (Optional): This is a real vector holding the rotation
% for the geometry in degrees, along each
% Cartesian axis. The rotations are performed
% clockwise. [Default: zeros(3, 1)].
% rot [numeric] (Optional): This is a real vector holding the rotation for
% the geometry in degrees, along each Cartesian
% axis. The rotations are performed clockwise.
% [Default: zeros(3, 1)].
%
% --------------------------------------------------
% Output
......@@ -81,11 +80,11 @@
% setup is one dimensional.
%
% --------------------------------------------------
function [vPos, vPosMesh] = virtMicGeo(gType, geoDim, nSens, xOff, yOff, zOff, orient)
function [vPos, vPosMesh] = virtMicGeo(gType, geoDim, nSens, trans, rot)
% ====================================================
% Check for number of arguments
% ====================================================
narginchk(1, 7);
narginchk(1, 5);
nargoutchk(0, 2);
% ====================================================
......@@ -97,7 +96,7 @@ function [vPos, vPosMesh] = virtMicGeo(gType, geoDim, nSens, xOff, yOff, zOff, o
% Validate optional arguments
if nargin > 1 && ~isempty(geoDim) && ~strcmpi(gType, "Single")
validateattributes(geoDim, "numeric", {'vector', 'real', 'nonnan', 'finite', 'nonempty', 'positive'}, mfilename, "Geometry dimensions", 2);
validateattributes(geoDim, "numeric", {'vector', 'real', 'nonnan', 'finite', 'nonempty', 'nonnegative'}, mfilename, "Geometry dimensions", 2);
if numel(geoDim) > 3 || numel(geoDim) == 2
error("The dimensions argument must be either a scalar or a vector with three elements");
......@@ -130,28 +129,16 @@ function [vPos, vPosMesh] = virtMicGeo(gType, geoDim, nSens, xOff, yOff, zOff, o
nSens = 10 * ones(3, 1);
end
if nargin > 3 && ~isempty(xOff)
validateattributes(xOff, "numeric", {'scalar', 'real', 'nonnan', 'finite'}, mfilename, "X-offset", 4);
else
xOff = 0;
end
if nargin > 4 && ~isempty(yOff)
validateattributes(yOff, "numeric", {'scalar', 'real', 'nonnan', 'finite'}, mfilename, "Y-offset", 5);
else
yOff = 0;
end
if nargin > 5 && ~isempty(zOff)
validateattributes(zOff, "numeric", {'scalar', 'real', 'nonnan', 'finite'}, mfilename, "Z-offset", 6);
if nargin > 3 && ~isempty(trans)
validateattributes(trans, "numeric", {'vector', 'real', 'nonnan', 'finite', 'nonempty', 'numel', 3}, mfilename, "Translation of the geometry", 4);
else
zOff = 0;
trans = zeros(3, 1);
end
if nargin > 6 && ~isempty(orient) && ~strcmpi(gType, "Single")
validateattributes(orient, {'numeric'}, {'vector', 'nonempty', 'nonnan', 'finite', 'real', 'numel', 3}, mfilename, "Geometry rotation around the Cartesian axes", 7);
if nargin > 4 && ~isempty(rot) && ~strcmpi(gType, "Single")
validateattributes(rot, {'numeric'}, {'vector', 'nonempty', 'nonnan', 'finite', 'real', 'numel', 3}, mfilename, "Geometry rotation around the Cartesian axes", 5);
else
orient = zeros(3, 1);
rot = zeros(3, 1);
end
......@@ -195,10 +182,10 @@ function [vPos, vPosMesh] = virtMicGeo(gType, geoDim, nSens, xOff, yOff, zOff, o
end
% Rotate
vPos = vPos * rotMat3d(-orient(1), -orient(2), -orient(3), "Degs");
vPos = vPos * rotMat3d(-rot(1), -rot(2), -rot(3), "Degs");
% Translate
vPos = vPos + [xOff, yOff, zOff];
vPos = vPos + trans(:).';
% For "Cube" geometry provide the coordinates in a "mesh format"
if nargout > 1 && strcmpi(gType, "Cube")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment