function [dq1,dq2,dq3,ddq1,ddq2,ddq3] = CinInvDif3R(xe,ye,dxe,dye,ddxe,ddye,d_incl,dd_incl,l1,l2,l3)

%-- Junta 1,2 -----------------------------------------------------------
for k=1:length(xe),
   
    %-- Junta do tornozelo/ankle ----------------------------------------
     k0 = xe(k)^2+ye(k)^2;
     k1 = k0+l1^2-l2^2;
     VAR_aux = 4.0*l1^2*k0-k1^2;
     if VAR_aux >= 0.0,       k2 = sqrt(VAR_aux);
     else disp('ERROR MSG1: function CinInvDif3R'), pause, return, end
     k3 = xe(k)*dxe(k)+ye(k)*dye(k);
     k4 = dxe(k)*dxe(k)+dye(k)*dye(k)+xe(k)*ddxe(k)+ye(k)*ddye(k);
     k5 = l1^2-l2^2-k0;
     k6 = xe(k)*dye(k)-ye(k)*dxe(k);
     k7 = xe(k)*ddye(k)-ye(k)*ddxe(k);
     k8 = (k0*k2^2)*((k4*k5)-(2.0*k3^2));
     k8 = k8-(k3^2*k5)*((2.0*k2^2)+(4.0*l1^2*k0)-(2.0*k0*k1));
     
      dq1(k) = k6/k0+(k3*k5)/(k0*k2);
     ddq1(k) = ( k0*k7-2.0*k3*k6 )/( k0^2 )+k8/( k0^2*k2^3 );

    %-- Junta do joelho/knee -------------------------------------------
     k0 = xe(k)^2+ye(k)^2;
     k1 = k0-l1^2-l2^2;
     VAR_aux = 4.0*l1^2*l2^2-k1^2;
     if VAR_aux >= 0.0,      k2 = sqrt(VAR_aux);
     else disp('ERROR MSG2: function CinInvDif3R'), pause, return, end
     k3 = xe(k)*dxe(k)+ye(k)*dye(k);
     k4 = dxe(k)^2+dye(k)^2+xe(k)*ddxe(k)+ye(k)*ddye(k);
     
      dq2(k) = 2.0*k3/k2;
     ddq2(k) = ( 2.0*k2^2*k4+4.0*k1*k3^2 )/( k2^3 );

    %-- Junta da anca/hip --------------------------------------------
     dq3(k) = d_incl(k)-dq1(k)-dq2(k);
     ddq3(k) = dd_incl(k)-ddq1(k)-ddq2(k);
     
 end  
%-------------------------------------------------------------------------
