Figuring out the angles that the segments should point is called "Inverse Kinematics"