Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
vec2axisdir.m
Go to the documentation of this file.
1% =========================================================================== %
2%> @brief convert a vector to an axis and a direction
3%>
4%> @param vec vector
5%>
6%> @retval axis axis (1, 2, 3)
7%> @retval dir direction (1, -1)
8%>
9%> @code
10%> [axis, dir] = vec2axisdir([1, 0, 0]) % returns "x", "positive"
11%> [axis, dir] = vec2axisdir([-1, 0, 0]) % returns "x", "negative"
12%> @endcode
13%>
14%> %> @copyright see the file @ref LICENSE in the root directory of the repository
15% =========================================================================== %
16function [axis, dir] = vec2axisdir(vec)
17
18arguments
19 vec (1,3) double
20end
21
22% check the vector
23assert(sum(abs(vec)) == 1, "The vector must be a unit vector")
24assert(max(abs(vec)) == 1, "The vector must align with an axis")
25
26% find the axis
27axis = find(vec);
28
29% find the direction
30dir = sign(vec(axis));
31
32end
function vec2axisdir(in vec)
convert a vector to an axis and a direction