Page MenuHome

FCurve with Quaternion keys does Cartesian Iinear interp rather than Spherical (very wrong results)
Closed, ArchivedPublic

Description

System Information
All operating systems.

Blender Version
Broken: 2.74 and earlier
Worked: none.

Short description of error

The FCurve implementation in Blender supports using quaternions (vec4) as keys. This is very nice and allows ones to use quaternions to specify the rotation of objects. But the FCurve primitive only supports two three types of interpolation, Constant, Linear and Bezier. The problem is that quaternions need to be interpolated using Spherical Linear Interpolation (AKA slerp), or Spherical Quadratic Interpolation (AKA squad). But from what I can tell is that blender actually uses Cartesian Linear interpolation on Quaternions. This generates proveably wrong answers. I am not sure if the best thing to do is add two new interpolation modes to FCurve (Slerp/Squad) or to add awareness of Quaternions Vec4s to FCurve so that Spherical interpolators are used for Linear (Slerp) and Bezier (Squad).

Either way this is a fundamental error in Blender that I think is relatively easy to fix.

Exact steps for others to reproduce the error


I've attached a *.blend file that demonstrates the issue.

The issue is reproduceable on the rotating text "TA" object between frames 50 and 60 as it is making a full smooth rotation. There are quaternions specified as keys for frames 50 and 60 and the orientation is correct at those frames, but the interpolated results from the FCurve are clearly wrong between 50 and 60 as the object wildly spins out of control in that time period. If Slerp or Squad interpolation was used by the FCurve instead of Cartesian Linear Interoplation the results would be correct.

Details

Type
Bug

Event Timeline

Ben Houston (bhouston) set Type to Bug.
Ben Houston (bhouston) created this task.
Ben Houston (bhouston) raised the priority of this task from to Needs Triage by Developer.

What we do in https://Clara.io is that we are aware of the type being interpolated. We interpolate a Vec4 as Cartesian Linear, and we interpolate a Quaternion using Slerp. This way you can still specify Linear or Cubic and we do it in the proper space (Cartesian vs. Spherical) as needed by the primitive type in the FCurve.

Do you want to make this in this way?

Perfection cat - I believe you've just reformulatedi it so that the non-linearity between is at the start and end of the rotation rather than in the middle of the rotation as it was in my scene. The bug in Blender's quaternion interpolation still exists., you are just working around it. It sort to sucks to have to work around the bug because you are asking users of Blender to be aware of when a quaternion interpolation can fail.

This really sounds more like a feature request to me… Yes, quaternions need slerp to have a 'natural' interpolation, but not having this feature is not a bug. @Joshua Leung (aligorith), what do you think?

Bastien Montagne (mont29) triaged this task as Normal priority.Jul 19 2015, 5:00 PM

It is up to you guys as to its priority.

Perfection Cat's workaround only works if you do a single rotation as he put the discontinuity at the beginning/end of the rotation rather than in the middle. If you want to do multiple revolutions using quaternions, I believe that Perfection Cat's workaround won't work because there is a discontinuity per revolution and you can not hid it at the beginning or end any more.

multiple revolutions using quaternions?


multiple revolutions is included in the right object.
A parent object and itself turn in the left object on a different axis.

Perfection Cat, neither of those objects are doing multiple revolutions. Multiple revolutions is like a car wheel that spins around multiple times as it is going down the road. The object on the right does a half turn and then turns back to its original position -- thus it never does more than a half revolution. The object on the right wiggles as well but is not spinning more than one revolution.

Can you make the "T" object spin around like a car wheel 5 times in a row using your method of finding quaternions that do not contain linear interpolation discontinuities? Something like this:

https://clara.io/view/62832505-ecde-4f46-90b0-bb2bbf4a09d1 (Hit play)

I added a python script which uses slerp

.

However this imposes new constraints ??? Keyframing channels individually would not be allowed for slerp. I.e.

w: A----B----C
x: A---------C
y: A---------C
z: A---------C

To calculate the slerp interpolation from A to B,
you would have to know the full quaternion at frame B
to calculate either the dot product between the quaternions
to find the angle:

angle = acos(dot(q0, q1))

or calculate the rotation difference:

dq = q0^(-1) * q1

Since the keyframes at frame B for the channels x, y, z miss
you would have to interpolate them from A and C.
The w-component of the resulting quaternion of this slerp interpolation
would have to match the existing keyframe at frame B
which renders this keyframe useless.

Am I wrong? How do you handle this? Did only read wikipedia articles yet.

Gyro Gearloose, I should say that I never understood why you deleted your original comment. I believe it was correct in that the issue also affects Angle Axis rotations.

Quaternions when used to representation rotations are supposed to be unit quaternions, thus always of length one. This imposes a restriction that you can not really animate a single element by itself, otherwise the result is actually not a unit quaternion, (unless you are only changing its sign and using constant discontinuous interpolation.)

In my experience, I've never seen a single element of a quaternion interpolated by itself in a useful context. Again this is because the majority of all quaternions generated by an Quaternion FCurve in which only a single element is interpolated does not generate unit quaterions (with the one exception described above) -- thus they are technically wrong. Normalizing a non-unit quaternion created will adjust its rotation value -- thus if you are creating non-unit quaternions you are not being precise in what you are specifying -- although I guess in some cases that doesn't matter, but most people want to know exactly what they are getting as a rotation result.

I misunderstood a meaning of "multiple revolutions" which you said.
I thought that it was a meaning to turn in plural axes.
It was a meaning to turn multiple it.

Neat stuff Perfection Cat. You did get it to rotate around in multiple revolutions. I've never seen anyone manually enter in Quaternions before. It is a little weird that so many of the manual quaternions you entered are non-unit -- these are not technically rotation quaterions -- see discussion in this paper: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

Did you know Perfection Cat that Quaternions were only introduced to the field of Computer Graphics because they enabled smooth interpolations via Slerp? Here is the original paper: https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf

If a fixed quantity turns it every time and adds a key frame, anyone can make it.
Even the present specifications of Blender only tried whether it was possible.

Perfection Cat, I can not understand what you are saying? Are you saying that you believe Slerp interpolation isn't required in Blender? Or whether with specially crafted keyframes of Quaternions you can avoid requiring Slerp?

The general case of being able to set arbitrary Quaternions into Blender (like in my original example I submitted with the error report) and having them reliably and smoothly interpolatie is broken because of Blender's lack of Slerp support. In other tools, such as ThreeJS, Maya, Softimage, Unity, etc do not have this limitation that Blender has because they have implemented correct Quaternion Slerp interpolation.

Sergey Sharybin (sergey) closed this task as Archived.
Sergey Sharybin (sergey) claimed this task.

Surely some improvements to interpolation of different rotation methods are possible, but it doesn't make existing interpolation methods to be wrong.

That being said, it's not really a bug, but a request for improvement, which is handled separately from the bug fixing process. Moving this to our TODO list now: http://wiki.blender.org/index.php/Dev:2.5/Source/Development/Todo/Animation#Animation_System

Thanks for the report anyway!