function Q = CinInvHip_Sup( P,L )

 %-- L=[l0 l1 l2 l3 l4 l5 l5h l5t l6] -------------------------------------
  l0 = L(1); l1 = L(2); l2 = L(3); l3 = L(4); l4 = L(5); 
  l5 = L(6); l5h = L(7); l5t = L(8); l6 = L(9);
 %-- Restriçao cinematica -------------------------------------------------  
  xh  = P(1);  yh = P(2);  zh = P(3); 
 %-- Junta lateral do tornozelo -------------------------------------------
  ang1 = atan2(-yh+l6/2,(zh-l0-l5-l5h/2));  
  if (ang1 > pi/4 & ang1 < 3*pi/4) | (ang1 < -pi/4 & ang1 > -3*pi/4)
      A = (-yh+l6/2)/sin(ang1)-l1-l4;
  else
      A = ( (zh-l0-l5-l5h/2)/cos(ang1)-l1-l4 );
  end
  
 %-- Junta sagital do tornozelo -------------------------------------------
  K1 = 2*l2*xh;
  K2 = 2*l2*A;
  K3 = xh^2+A^2+l2^2-l3^2;
  KK_aux = K1^2+K2^2-K3^2;
  if KK_aux < 0, disp('ERROR MSG: function CinInv12R'), pause, return, end
  ang2 = atan2(K1,K2)+atan2(sqrt(K1^2+K2^2-K3^2),K3);
  %-- Ângulo entre -pi e pi -----------------------------------------------
  if ang2 >  pi,    ang2 = ang2-2*pi;   end
  if ang2 < -pi,    ang2 = ang2+2*pi;   end
  
 %-- Junta do joelho ------------------------------------------------------
  K1 = 0;
  K2 = 2*l2*l3;
  K3 = xh^2+A^2-l2^2-l3^2;
  KK_aux = K2^2-K3^2;
  if KK_aux < 0, disp('ERROR MSG: function CinInv12R'), pause, return, end
  ang3 = -atan2(sqrt(K2^2-K3^2),K3);
     
 %-- Juntas da anca -------------------------------------------------------
  ang4 = -ang2-ang3; 
  ang5 = -ang1;
  ang6 = 0;

%-- Vector de juntas ------------------------------------------------------
  Q = [ ang1 ang2 ang3 ang4 ang5 ang6 ];
%-----------------------------------------------------------------------end
