function Q=invkinRRR(x,y,phi,L1,L2,L3)
Pwx=x-L3*cos(phi);
Pwy=y-L3*sin(phi);

the2=acos((Pwx^2+Pwy^2 - L1^2-L2^2)/(2*L1*L2));
q2A=the2;
the1=atan2(Pwy*(L1+L2*cos(the2))-Pwx*L2*sin(the2),Pwx*(L1+L2*cos(the2))+Pwy*L2*sin(the2));
q1A=the1;
q3A=phi-q1A-q2A;

the2=-acos((Pwx^2+Pwy^2 - L1^2-L2^2)/(2*L1*L2));
q2B=the2;
the1=atan2(Pwy*(L1+L2*cos(the2))-Pwx*L2*sin(the2),Pwx*(L1+L2*cos(the2))+Pwy*L2*sin(the2));
q1B=the1;
q3B=phi-q1B-q2B;
Q=[q1A q1B;q2A q2B;q3A q3B];
end