When converting any rotation controller to an Euler controller it is possible for sign flips to occur in the resulting animation. This is due to the fact that one single rotation matrix can be expressed through many different triplets of Euler angles. Sometimes the produced Euler angles are not interpolatable. There is code in the SDK which solves this problem. It samples the whole animation range and produces Euler angles that result in the same animation as the original, if interpolated. This code is generally valuable for developers who want to convert keys of any type of 3ds Max controller that uses quaternions internally into a Euler angle keys (for example an export plugin).
The code can be found in \MAXSDK\SAMPLES\CONTROLLERS\EULRCTRL.CPP in the method EulerRotation::Copy(). The algorithm works as follows:
The code samples the entire animation range and incrementally adds up the angles for each time step. During resampling it detects possible sign flips by comparing the Euler/Quat ratio of two successive time steps. The Euler/Quat ratio is the relation of the angle difference in Euler space to the angle difference in Quat space. If this ratio is bigger than PI the rotation between the two time steps contains a flip. The Euler/Quat ratio can be determined using the SDK functions GetEulerQuatAngleRatio() or GetEulerMatAngleRatio(). If a flip is detected the algorithm calculates the actual angle not containing a flip and adds it to the incremental angle.
The actual detection of the flip is dependent on the amount of rotation in between the time steps. It is obvious, that the smaller the time step, the more accurate the detection is. In the code described above a time step of 1 tick is used, which is most accurate, but also most time intensive. The THRESHHOLD value describes the maximum intended rotation allowed between two time increments. In the code described above the threadshold is 1.0 which is equal to 57 degrees of rotation (a lot of rotation for one tick).