Encountered the same problem when trying to smooth 3D camera tracking orientation values, I used this expression to fix the issue. I’m guessing it breaks at the 180 degree rotation point, but at least the usual 0 to 360 flip is fixed by this.
n = 24;// number of frames to smooth in each direction
fps = 24;
xRot = 0;
yRot = 0;
zRot = 0;
for (i=-n; i < n+1; i++) {
xRotT = (transform.orientation.valueAtTime(time+i/fps)[0]+180)%360;
yRotT = (transform.orientation.valueAtTime(time+i/fps)[1]+180)%360;
zRotT = (transform.orientation.valueAtTime(time+i/fps)[2]+180)%360;
xRot += xRotT;
yRot += yRotT;
zRot += zRotT;
}
xRot = xRot/(n*2+1)-180;
yRot = yRot/(n*2+1)-180;
zRot = zRot/(n*2+1)-180;
[xRot, yRot, zRot]
Kalleheikki Kannisto
Senior Graphic Designer