Comments in the ik solver source code explain all the math. A simple example applet creates the demo below. The applet uses matrix math and double buffering.
In the demo below, when no IK solution is possible the link arm turns red.
Instructions: drag the mouse to change viewpoint.