Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
axisdir2vec.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @brief convert an axis and a direction to a vector
3%>
4%> @param axis axis (x, y, z) or number (1, 2, 3)
5%> @param dir direction (positive, negative) or number (1, -1)
6%>
7%> @retval vec vector
8%>
9%> @code
10%> vec = axisdir2vec("x", "positive") % returns [1, 0, 0]
11%> vec = axisdir2vec(1, -1) % returns [-1, 0, 0]
12%> @endcode
13%>
14%> %> @copyright see the file @ref LICENSE in the root directory of the repository
15% =========================================================================== %
16function vec = axisdir2vec(axis, dir)
17
18% check the axis
19if ischar(axis) || isstring(axis)
20 axis = axis2num(axis);
21elseif ~isnumeric(axis)
22 error("The axis must be a number or a string")
23end
24
25% check the direction
26if ischar(dir) || isstring(dir)
27 dir = direction2num(dir);
28elseif ~isnumeric(dir)
29 error("The direction must be a number or a string")
30end
31
32% create the vector
33vec = zeros(1,3);
34vec(axis) = sign(dir);
35
36end
function axis2num(in axis)
convert an axis to a number
function axisdir2vec(in axis, in dir)
convert an axis and a direction to a vector
function direction2num(in dir)
convert a direction to a number