I implemented the Cyclic Coordinate Descent (CCD) method for inverse kinematics. The basic idea behind CCD is to iteratively change 1 degree of freedom at a time, starting at the bone closest to the end effector.
I used an euler angle representation for the joints, attempting to change one degree of freedom (X, Y, Z rotations) at a time. Unfortunately, I was unable to get full 3D working, though the models and algorithm have been built with 3D in mind. The demo is mostly in the 2D XY plane, and a small bit in the Z plane.
I created a 3d model to have a nicer visual output (and for easier debugging!). The short end is the parent and the long end points towards the child, if it exists. In addition, you can use the arrow keys and WASD to move around the scene.
The system gracefully handles situations that are out of reach, opting to stretch the joints as far as possible for an optimal solution. See the screenshots below for an example, or watch the video.
You can specify (in the code, as a constant) whether to fix some of the joints to be completely stationary (as seen in the video). However, this is only a binary flag - you can either allow full 360-degree movement or none at all.