function Q = InverseKinematics( P_arrow,L )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
l1 = L(1); l2 = L(2); l3 = L(3);
%__________________________________________________
q1 = atan2(P_arrow(2),P_arrow(1));%teta1

if abs(q1) <pi/4 || abs(q1) > 3*pi/4,          
    k1 = P_arrow(1)*l3;
    k2 = (l1-P_arrow(3))*l3*cos(q1);
    k3 = -l2*l3*cos(q1);
    if P_arrow(1) >= 0, 
       q2 = atan2(k1,k2)-atan2(sqrt(k1^2+k2^2-k3^2),k3);    
    else
         q2 = atan2(k1,k2)+atan2(sqrt(k1^2+k2^2-k3^2),k3);    
    end
else    
      k1 = P_arrow(2)*l3;
      k2 = (l1-P_arrow(3))*l3*sin(q1);
      k3 = -l2*l3*sin(q1);
      if P_arrow(2) >= 0,
         q2 = atan2(k1,k2)-atan2(sqrt(k1^2+k2^2-k3^2),k3);
      else
            q2 = atan2(k1,k2)+atan2(sqrt(k1^2+k2^2-k3^2),k3);
      end
end

Q = [q1 q2]';
%__________________________________________________
end

