function [ang1,ang2,ang3,ang4,ang5] = CinInv5dof(x3,y3,z3,l0,l1,l2,l3,l4,l5)

%-- Junta do tornozelo e joelho -------------------------------------------
for k=1:length(x3),
   
 %-- Junta lateral do tornozelo -------------------------------------------
  ang1(k) = atan2(-y3,z3);  
  if (ang1(k) > pi/4 & ang1(k) < 3*pi/4) | (ang1(k) < -pi/4 & ang1(k) > -3*pi/4)
      A = y3(k)/sin(ang1(k))+l1;
  else
      A = -( z3(k)/cos(ang1(k))-l1 );
  end
  
 %-- Junta sagital do tornozelo -------------------------------------------
  k1_2 =  2*l2*x3(k);
  k2_2 = -2*l2*A;
  k3_2 = x3(k)^2+A^2+l2^2-l3^2;
  kk_aux = k1_2^2+k2_2^2-k3_2^2;
  if kk_aux < 0, disp('ERROR MSG: function CinInv5R'), pause, return, end
  ang2(k) = atan2(k1_2,k2_2)+atan2(sqrt(k1_2^2+k2_2^2-k3_2^2),k3_2);
  
 %-- Junta do joelho ------------------------------------------------------
  k1_3 = 0;
  k2_3 = 2*l2*l3;
  k3_3 = x3(k)^2+A^2-l2^2-l3^2;
  kk_aux = k2_3^2-k3_3^2;
  if kk_aux < 0, disp('ERROR MSG: function CinInv5R'), pause, return, end
  ang3(k) = -atan2(sqrt(k2_3^2-k3_3^2),k3_3);
  
 %-- Ângulos entre -pi e pi -----------------------------------------------
  if ang2(k) >  pi,    ang2(k) = ang2(k)-2*pi;   end
  if ang2(k) < -pi,    ang2(k) = ang2(k)+2*pi;   end
   
 %-- Juntas da anca -------------------------------------------------------
  ang4(k) = -ang2(k)-ang3(k); 
  ang5(k) = -ang1(k);
end  
%-----------------------------------------------------------------------end
