function angle = getAngleFromVector2(v)
%GETANGLEFROMVECTOR2 Angle of 2D vector.
%   ANGLE = GETANGLEFROMVECTOR2(V) returns the angle (in radians) between
%   the vector [1 0] and the given vector V.
%   The result is in [0, 2*pi[.

%   Author: Damien Teney

v = v / norm(v);
angle = acos(v(1)); % In [0, pi]
if v(2) < 0
  angle = -angle; % In [-pi, +pi]
end

angle = mod(angle, 2 * pi); % In [0, 2*pi[
