Hey...there are so many genius in math out there. I'm convinced if you would show your actual piece of code for the joint constraints and give a short explenation of your struggles to such a genius, you 'll get help. Being able to set proper joint limits would be quite important to me as I like using the IK-tool for animating.
I'm pretty sure the guy who is making Anim8tor (Steven Glanville) could give you some hints on solving this problem very fast;) His e-mail: support(AT)anim8or.com . Why catching a headache for reinventing the wheel when it already has been invented

From the Anim8tors page:
" Sometimes rotation is not quite a simple as giving the first and last positions and letting the computer figure out what to do in between. For constrained joints (those with limits on how they can be rotated) like the one at the right, things are simple. Moving from position A to position B simply rotates to the right.

However for a free or unconstrained rotation this doesn't quite work. There are two directions that the joint can move: clockwise or counter clockwise.
Anim8or resolves this dilemma by expanding the range of angles that you can use to be from -360 degrees to +360 degrees. There are then two values that represent the same position. One-quarter turn to the right is either +90 or -270. If the difference between the angles of less than 360 degrees, the joint simply moves between the two. If it's greater than 360 degrees then the joint moves the opposite way. It's not really as confusing as it seems once you've tried it out a time or two.
