% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %
% function_calculateAngle calculates the angle of every point existing is  %
% "SetOfPoints" regarding the "PointOfInterest". This is the angle that    %
% both points make with the x axis:                                        %
%       Example:                                                           %
%       ==============================================================     %
%       ||2nd Q  |                                      1st Quadrant||     %
%       ||       |                                                  ||     %
%       ||       |PointOfInterest                                   ||     %
%       ||-------x----)----------------------------------------XAxis||     %
%       ||       |\***) <---- Angle                                 ||     %
%       ||       | \*)                                              ||     %
%       ||       |  \                                               ||     %
%       ||       |   \                                              ||     %
%       ||       |    \  SetOfPoint(i)                              ||     %
%       ||       |     x                                            ||     %
%       ||     YAxis                                                ||     %
%       ||3rd Q  |                                      4th Quadrant||     %
%       ==============================================================     %
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %

%  INPUTS:   Name           | Type    | Dimensions | Description
%            PointOfInterest| 1Point  | 1x2        | Angle to Study
%            SetOfPoints    | nPoints | nx2        | Points to Calculate Angle from
%
% OTUPUTS:   Name           | Type    | Dimensions | Description
%            t              | int     | 1x1        | Nbr of Calculated Angles
%            Angle          | nAngles | 1xt        | Calculated Angles



function Angle = function_calculateAngle2(PointOfInterest, SetOfPoints)
    t = 0;
    for i = 3:size(SetOfPoints,1);
    t = t+1;
        P0 = SetOfPoints(1,1:2);
        P1 = SetOfPoints(2,1:2);
        P2 = SetOfPoints(i,1:2);
        Angle(t) = atan2(abs(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)) * 180/pi;
        if(abs(Angle(t) > 180))
            Angle(t) = Angle(t) - 360*sign(Angle(t));
        end
    end
end