FCurve with Quaternion keys does Cartesian Iinear interp rather than Spherical (very wrong results) #45473

Closed
opened 2015-07-17 20:52:41 +02:00 by Ben Houston · 23 comments

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

badQuaternionInterpolation.blend
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.

**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** [badQuaternionInterpolation.blend](https://archive.blender.org/developer/F207772/badQuaternionInterpolation.blend) 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.
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @bhouston

Added subscriber: @bhouston
Author

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.

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.

Added subscriber: @pink.vertex

Added subscriber: @pink.vertex

This comment was removed by @pink.vertex

*This comment was removed by @pink.vertex*

Added subscriber: @sindra1961

Added subscriber: @sindra1961

Do you want to make this in this way?
A_QuaternionInterpolation.blend

Do you want to make this in this way? [A_QuaternionInterpolation.blend](https://archive.blender.org/developer/F208474/A_QuaternionInterpolation.blend)
Author

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.

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.

Added subscribers: @JoshuaLeung, @mont29

Added subscribers: @JoshuaLeung, @mont29

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. @JoshuaLeung, what do you think?

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. @JoshuaLeung, what do you think?
Author

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.

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?
TwoAxisRotate.blend
multiple revolutions is included in the right object.
A parent object and itself turn in the left object on a different axis.
{F210920}{F210922}TwoAxisRotate3.png

multiple revolutions using quaternions? [TwoAxisRotate.blend](https://archive.blender.org/developer/F210915/TwoAxisRotate.blend) multiple revolutions is included in the right object. A parent object and itself turn in the left object on a different axis. {[F210920](https://archive.blender.org/developer/F210920/TwoAxisRotate1.png)}{[F210922](https://archive.blender.org/developer/F210922/TwoAxisRotate2.png)}![TwoAxisRotate3.png](https://archive.blender.org/developer/F210924/TwoAxisRotate3.png)
Author

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)

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 TwoAxisRotate_Python.blend.

TwoAxisRotate_Python.blend.png

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.

I added a python script which uses slerp [TwoAxisRotate_Python.blend](https://archive.blender.org/developer/F211196/TwoAxisRotate_Python.blend). ![TwoAxisRotate_Python.blend.png](https://archive.blender.org/developer/F211199/TwoAxisRotate_Python.blend.png) 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 ](https://en.wikipedia.org/wiki/Slerp) yet.
Author

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.

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.
{F211429}MultipleRevolutions.blend

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. {[F211429](https://archive.blender.org/developer/F211429/MultipleRevolutions.png)}[MultipleRevolutions.blend](https://archive.blender.org/developer/F211431/MultipleRevolutions.blend)
Author

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

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.

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.
Author

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.

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.

Added subscriber: @Sergey

Added subscriber: @Sergey

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2015-09-04 12:56:33 +02:00

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!

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!
Member

Added subscriber: @Stefan_Werner

Added subscriber: @Stefan_Werner
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#45473
No description provided.