   IK Problem
  Hi,allI am implementing a IK system using CCD methodNow I encouter a problem.I want to apply constraint to joints by using euler angle.But I found that euler is not unique.A rotation can be represented by using many euler angles.How can I solve this problem?How can I apply constraint on joints by using euler angle?   
  some body help me   ;  T_T   ;  What happens if you convert your euler angles to quaternions?  Then apply your constraints that way.   ;  All your joints will need a certain number of degrees of freedom. Each of these degrees of freedom should have a deterministic euler angle value. Any time you compare the axis angles it should be in the "common denominator" form.As you said there are many ways to represent the same orientation with euler angles, but if you always "reduce" them into the most basic form, then they will be compareable.For example, a hinge joint only has one very clear axis of rotation, if you always convert the current position and axis limits to be about that axis, then it's very easy to compare them to see if you're at or exceeded the axis limits.A universal joint is just two hinge joints put together. A ball joint is a tad more complex, not having a number of axis of rotation you can either: construct it from 3 hinges combined in a very specific order. Or you can compare the joint position geometrically. This is what havok allows you to do for the ragdoll joints. The ball joint starts with a cone of freedom. then you can intersect that cone with other cones in boolean operations creating complex joint limits. These cannot exactly be compared with euler angles. They are cones, the cones may be at euler angles to each other, it'll also be about a particular axis. You may need to expand your interpretation of "using euler angles".   ;  Thanks for your reply.Assume that I have two euler angle rotate in pitch yaw roll orderEulerAngle( 180.0f, 90, 90 )EulerAngle( 90.0f 90.0f, 0.0f )These are the same goemerty meaning.When the bone rotated by some angle, these will happen.I can only clamp the angle to one specific EulerAngle.But now has two euler angle of very different form.How can i compute the constraint angle?I need two different constraint angle?These will happen especially when one angle is 180 degree.   ;  For IK it's very easy since you wouldn't allow those two different solutions to be presented. If a robot has 3 axes, they are combined in a specific order. ABC. When doing cycling decent you'd move A, then B, then C. A has some limited motion, as does B and C. You'll end up with various different sets of ABC values, multiple sets may even provide what appears to be identical results. But it's still simply A, B, and C. And you can very easily constrain them individually.So if ABC set 1 and ABC set 2 have the same end effector position, and you arrived at them, then each axes would have been incremented individually within its axis constraints.You need to describe your rotations like this://constrain anglepitchAngle = Clamp(pitchAngle, pitchLowLimit, pitchHighLimit);//3 individual rotationsAxisAngle pitch(pAxis, pitchAngle);AxisAngle yaw(yAxis, yawAngle);AxisAngle roll(rAxis, rollAngle);//combined in an explicit order for final orientationQuaternion final = Quaternion(pitch) * Quaternion(yaw) * Quaternion(roll);Constraint the angles about specific axes, and then combine them to get your final transform.Yes, you will have different pitch, yaw, and roll angles which will have the same end effector location. But when decomposed, it's trivial to apply individual constraints.If you're having an issue where the artist has more (or different) flexibility then your ik system. Then you'll need a deterministic way to decompose the final transform into your angles about explicit axes.Such that the end orientation represented by your two examples:EulerAngle( 180.0f, 90, 90 )EulerAngle( 90.0f 90.0f, 0.0f )When decomposed by your decomposition alogorithm, will always result in only one of those angle sets. It is having this deterministic decomposition algorithm which makes using euler angles even possible.   ;  Also, just to shed some light on the geometric approach.Say you wanted to constrain your 3axis joint. By default it can move in a sphere using two of its axes. Using the dot product it's very easy to constrain the joint to within a portion of that sphere by using a reference vector. If you want to constrain the orientation to the upper hemisphere. You'd create a vector representing the orientation, point to the "end effector." Then using the dot product against the up reference vector. You can limit the dot product outcome using an angle. 90degrees in our case. If the dot product exceeds 90 degrees the joint has violated its constraint.You can compute the correction value by using the cross product between the orientation vector and the reference vector. The result will be an axis and an angle to align your orientation to the reference, and you can determine how much of that to reintroduce to restore the constraint.Projecting the correction value back into the machines actual axes is a bit more complex, but you shouldn't allow the constraint to be violated in the first place.   ;  I think I am not quite understand.I'll show some pseudocode.void rotateBone( Bone& bone, Quaternion& angleToRotate ){    Quaternion localRotationQuat = bone.getRotation();    Quaternion destRotationQuat = localRotation * angleToRotate;    EulerAngle destRotaionAngle = destRotationQuat.toEulerAngle();Constraint& constraint = bone.getConstraint();    EulerAngle& minConstraintAngle = constraint.getMinAngle();    EulerAngle& maxConstraintAngle = constraint.getMaxAngle();destRotationAngle.clamp( minConstraintAngle );    destRotationAngle.clamp( maxConstraintAngle );destRotationQuat.setupFromEulerAngle( destRotationAngle );    bone.setRotation( destRotationQuat );}Well, my problem is,if current rotation angle of the bone is EulerAngle( 180.0f, 90, 90 ),but after this line,   Quaternion destRotationQuat = localRotation * angleToRotate;If I translate the quatenion to euler angle,the euler angle becomes something like ( -50, 10, -170 )it is a violation of my constraint, so i will clamp it,but infact, if i don't clamp it,though the rotation of some axis is invalid,but the rotation result of 3 axis is corret.If i clamp one axis to the constraint,the result is within my constrait, but it is not the position I want.So I don't understand it.And what is the "deterministic decomposition algorithm" ?And I found that when two bone and dest position is colinear, ccd method dosen't work.I will post another thread.Please help me, thanks a lot.[Edited by - MGL on May 15, 2009 12:46:09 AM];  if the orienation of your joints is only stored as a quaternion then your best approach will be geometrical. It really all depends on the robot. If it were 3 single axis joints combined i think you could solve that problem. But the problem is you are using 1 completely universally rotateable joint. I have to assume your demo is a chain of ball joints which will reach the target but always ends up in completely unpredictable configurations? due to the large number of spherical joints.either way, if you're using spherical joints, this page should give you some good ideas on how to constrain them using the geometrical, or cone based approach i mentioned earlier.http://www.cguu.com/3dsmax/3dsmax6/reactor/ragdoll.html