function ang3 = OptMovTronco( T1,q1,q2,l1,l2,l3,r1,r2,r3,m1,m2,m3,go )

%-- Determinaçao do angulo teta3 (tronco) ---------------------------
 k1 = -go*m3*l3*sin( q1+q2 );
 k2 =  go*m3*l3*cos( q1+q2 );
 k3 = T1-go*( (m1*r1+(m2+m3)*l1)*cos(q1)+(m2*r2+m3*l2)*cos(q1+q2) );

 AUX = k1.^2+k2.^2-k3.^2;
 I = find(AUX < 0);
 if ~isempty(I)
    disp('ERROR MSG: function OptMovTrinco'), pause
    return
 end
      
 ang3 = atan2(k1,k2)+atan2(sqrt(k1.^2+k2.^2-k3.^2),k3);
 
 for k=1:length(ang3),
 %-- Ângulos entre -pi e pi ---------------------------------------------
   if ang3(k) >  pi,    ang3(k) = ang3(k)-2*pi;   end
   if ang3(k) < -pi,    ang3(k) = ang3(k)+2*pi;   end
 end
%------------------------------------------------------------------end
