For inverse kinematic, I have seen this :
This algorythm use the law of cosinus and pythagore theorem.