# Unroll rotations?

This topic is 1674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can someone explain in pseudo code or the math how this might work.  It's called Unroll Rotations:

"Compensates for gimbal locking effects by unrolling rotations. Unroll Rotations is designed to clean motion capture data that contains
large rotations which cause flipping or shaking in animations."

Basically, what's given, is 3 rotation curves (x,y,z) expressed in Euler angles.  These curves are initially locked to -180 to 180 degrees.  After unrolling, this limitation is removed.

What I don't understand about this is, why do they focus on the Y curve?  Aren't these curves unrolled independently of each other?   If not, then how does unrolling one curve affect the other? I just don't understand the "unrolling" algorithm used here.

##### Share on other sites
It appears that it looks for a quick change in velocity in the y angle when it gets near 0. Notice the sharp change in direction on the green line in figure A. If it detects that sharp change then it makes all of the following y values negative then adjusts the x and z to make the orientation the same with the new y angle.

Without diving into more detail about Euler angles, what do you need this for? Odds are you can have a much cleaner and easier to manage solution using Quaternions.

##### Share on other sites

It appears that it looks for a quick change in velocity in the y angle when it gets near 0. Notice the sharp change in direction on the green line in figure A. If it detects that sharp change then it makes all of the following y values negative then adjusts the x and z to make the orientation the same with the new y angle.

Without diving into more detail about Euler angles, what do you need this for? Odds are you can have a much cleaner and easier to manage solution using Quaternions.

Thanks, I would prefer to use quaternions, but my problem is importing it into a 3D modelling app that doesn't use them.
They want Euler angles probably because they're easier for humans to read on a graph.

I can convert quaternions to Euler angles, but a new problem arises.  Conversion limits all values -180 to 180 degrees.
This causes rotation to become more susceptible to flipping.  But, we can fix this by unrolling the curve to make it more continuous.

If it detects that sharp change then it makes all of the following y values negative then adjusts the x and z to make the orientation
the same with the new y angle.

That's what I don't fully understand.   Exactly, how does a change in y affect x and z?

If you have known Euler angles (x,y,z), and change y, how to re-compute x and z, but still keep the same orientation?
I don't think they're just adding 360 degrees to all of them?

Edited by sevenfold1

##### Share on other sites
In order to give you a concrete answer I would have to know the three axis that are used for the euler angles. Look on Wikipedia if you need clarification on what I mean. The angle system could be z-x-z, z-y-z, ect..

A more general answer. Grab a pen or pencil near you. Hold it so it is facing up. We will then define the three axis used.

First degree of freedom is rotating the pen so it still faces up.
Second tilt the pen down either towards, or away from you but not side to side
Last rotate the pen on the same axis as the first time, but because the pen is tilted down this time it will change where it is pointed.

this is a z-x-z euler angle configuration.

In the filter it appears to allow the pen to rotate toward and away from you in the second rotation whereas before it only was allowed to tilt towards you.

So lets get to the same orientation one with the restriction, one without.

Go to the starting position, rotate the pen 180 degrees along the first axis. Then tilt the pen toward you 45 degrees. Lastly rotate the pen around the first axis again 180 degrees. At this point the pen should be pointed away from you 45 degrees.

So after you apply the filter the angles change to no rotation on the first, tilt back 45 degrees on the second, and no rotation on the last. While I would have to play with my pen more to verify this it appears to keep the same orientation with the new y rotation you simply add 180 degrees to the first rotation, negate the second rotation, and subtract 180 degrees from the third rotation.

Go ahead and play around with your pen to make sure this works. Edited by HappyCoder

##### Share on other sites

Thanks, I think it is X,Y,Z.  I found some short descriptions on how it works:

The Unroll filter works with a set of 3 rotation curves, or it can also be passed a KFbxAnimCurveNode.
The curves are expected to be in the order X,Y,Z, regardless of the node's rotation order. The rotation curves
are unrolled with priority on the Y axis... or whichever curve is in the second position.

Basically, the idea is that an axis Y is priviledged for the rotations to be unrolled.
Instead of being limited to -180, 180, the values of the keys for this axis' curve are unrolled as needed,
as high or as low as needed. The other two axis' curves are adjusted accordingly.

The Unroll filter is used to remove gimbal locks. This filter requires 3 rotation curves in the same Apply call.
This filter expects to work with interdependent curves. The curves are expected to be in the X,Y,Z order regardless
of the node’s rotation order. The rotation curves are unrolled with priority on the Y-axis... or whichever curve
is in the second position.

I will play around with 180 degrees and see if my results matches what they're doing.