function Q=invkinRRR2(x,y,z,L1,L2,L3)

%solução 1
q3=asin((x^2+y^2+(z-L1)^2 - L3^2-L2^2)/(2*L2*L3));

if imag(q3)~=0
    Q=NaN;
    return
end
r=sqrt(x^2+y^2);
N=((L3*cos(q3)*(z-L1))-(r*(L2+L3*sin(q3))));
D=((z-L1)*(L2+L3*sin(q3)) + L3*cos(q3)*r);
q2=atan2(N,D);

N=y*((L3*cos(q3+q2))-(L2*sin(q2)));
D=x*((L3*cos(q3+q2))-(L2*sin(q2)));
q1=atan2(N,D);

qA1=q1;
qA2=q2;
qA3=q3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%solução 2
q3=pi-asin((x^2+y^2+(z-L1)^2 - L2^2-L3^2)/(2*L2*L3));

if imag(q3)~=0
    Q=NaN;
    return
end
r=sqrt(x^2+y^2);
N=(L3*cos(q3)*(z-L1)-r*(L2+L3*sin(q3)));
D=((z-L1)*(L2+L3*sin(q3)) + L3*cos(q3)*r);
q2=atan2(N,D);

N=y*((L3*cos(q3+q2))-(L2*sin(q2)));
D=x*((L3*cos(q3+q2))-(L2*sin(q2)));
q1=atan2(N,D);

qB1=q1;
qB2=q2;
qB3=q3;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%solução 3
q3=asin((x^2+y^2+(z-L1)^2 - L2^2-L3^2)/(2*L2*L3));

if imag(q3)~=0
    Q=NaN;
    return
end
r=-sqrt(x^2+y^2);
N=(L3*cos(q3)*(z-L1)-r*(L2+L3*sin(q3)));
D=((z-L1)*(L2+L3*sin(q3)) + L3*cos(q3)*r);
q2=atan2(N,D);

N=y*((L3*cos(q3+q2))-(L2*sin(q2)));
D=x*((L3*cos(q3+q2))-(L2*sin(q2)));
q1=atan2(N,D);

qC1=q1;
qC2=q2;
qC3=q3;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%solução 4

q3=pi-asin((x^2+y^2+(z-L1)^2 - L2^2-L3^2)/(2*L2*L3));

if imag(q3)~=0
    Q=NaN;
    return
end
r=-sqrt(x^2+y^2);
N=(L3*cos(q3)*(z-L1)-r*(L2+L3*sin(q3)));
D=((z-L1)*(L2+L3*sin(q3)) + L3*cos(q3)*r);
q2=atan2(N,D);

N=y*((L3*cos(q3+q2))-(L2*sin(q2)));
D=x*((L3*cos(q3+q2))-(L2*sin(q2)));
q1=atan2(N,D);

qD1=q1;
qD2=q2;
qD3=q3;

Q=[qA1 qB1 qC1 qD1; qA2 qB2 qC2 qD2; qA3 qB3 qC3 qD3];
end