BLI_math: improve the threshold for wrapping rotation in compatible_eul #104856

Closed
Campbell Barton wants to merge 1 commits from ideasman42:pr-euler-compat into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Having a threshold well above PI would result in discontinuity in some cases.

The discontinuity can be measured by generating euler values (both random and interpolated rotations), then comparing the accumulated difference.
Changing the threshold for wrapping rotations produces at least as good or more compatible results.

This was reported as #17297 and fixed in 0, however the change was only applied for the game-engine.

Ref !104856


The attached script can be run from the command line, reporting:

blender -b --python  measure_compat_eul.py 

The output is:

Interpolated eulers 1.1463990949094296
Random eulers 4.888162368731574

After the change the output is:

Interpolated eulers 1.1338555704057216
Random eulers 4.614090494234115

(lower is better).

This is a simpler case:

from mathutils import Euler

e_prev = Euler((-12.991190910339355, -48.46185302734375, 41.59339904785156))
e_test = Euler((-16.96780014038086, 1.3109626770019531, -6.306068420410156))
e_compat = e_test.copy()
e_compat.make_compatible(e_prev)
print(tuple(e_compat), "difference:", sum([abs(a - b) for a, b in zip(e_prev, e_compat)]))

# Before: (-16.96780014038086, -48.95452117919922, 43.959415435791016) difference: 6.835293769836426
# After: (-10.684614181518555, -48.95452117919922, 43.959415435791016) difference: 5.165261268615723
Having a threshold well above PI would result in discontinuity in some cases. The discontinuity can be measured by generating euler values (both random and interpolated rotations), then comparing the accumulated difference. Changing the threshold for wrapping rotations produces at least as good or more compatible results. This was reported as #17297 and fixed in [0], however the change was only applied for the game-engine. Ref !104856 [0]: ab44742cf36639b73f1aa2c18aa55b14ff059acd ---- The attached script can be run from the command line, reporting: ``` blender -b --python measure_compat_eul.py ``` The output is: ``` Interpolated eulers 1.1463990949094296 Random eulers 4.888162368731574 ``` After the change the output is: ``` Interpolated eulers 1.1338555704057216 Random eulers 4.614090494234115 ``` (lower is better). This is a simpler case: ``` from mathutils import Euler e_prev = Euler((-12.991190910339355, -48.46185302734375, 41.59339904785156)) e_test = Euler((-16.96780014038086, 1.3109626770019531, -6.306068420410156)) e_compat = e_test.copy() e_compat.make_compatible(e_prev) print(tuple(e_compat), "difference:", sum([abs(a - b) for a, b in zip(e_prev, e_compat)])) # Before: (-16.96780014038086, -48.95452117919922, 43.959415435791016) difference: 6.835293769836426 # After: (-10.684614181518555, -48.95452117919922, 43.959415435791016) difference: 5.165261268615723 ```
Author
Owner

@blender-bot build linux

@blender-bot build linux
Campbell Barton force-pushed pr-euler-compat from 5ec3796d74 to 2f59e96d37 2023-02-17 09:18:17 +01:00 Compare
Campbell Barton changed title from WIP BLI_math: correct the threshold for wrapping rotation in compatible_eul to WIP BLI_math: improve the threshold for wrapping rotation in compatible_eul 2023-02-17 09:25:12 +01:00
Campbell Barton changed title from WIP BLI_math: improve the threshold for wrapping rotation in compatible_eul to BLI_math: improve the threshold for wrapping rotation in compatible_eul 2023-02-17 09:47:28 +01:00
Author
Owner

Committed c6ea00de3c, closing.

Committed c6ea00de3cd4ee01a5c2070f5aadcf0aa7b661c4, closing.
Campbell Barton closed this pull request 2023-02-17 09:53:16 +01:00
Campbell Barton deleted branch pr-euler-compat 2023-02-17 09:53:25 +01:00

Following up on this. It seems like just doing this is even doing better.

void compatible_eul(float eul[3], const float oldrot[3])
{
  for (uint i = 0; i < 3; i++) {
    eul[i] = angle_wrap_rad(eul[i] - oldrot[i]) + oldrot[i];
  }
}

This is the result:

Interpolated eulers 1.1338555291295052
Random eulers 4.614090291559696

Comparing with higher precision (ROTATIONS = 10000)

// Simple wrap
Interpolated eulers 0.8127715403175354
Random eulers 4.698880729122162
// Current wrap
Interpolated eulers 0.812771551511623
Random eulers 4.698880809928011
Following up on this. It seems like just doing this is even doing better. ``` void compatible_eul(float eul[3], const float oldrot[3]) { for (uint i = 0; i < 3; i++) { eul[i] = angle_wrap_rad(eul[i] - oldrot[i]) + oldrot[i]; } } ``` This is the result: ``` Interpolated eulers 1.1338555291295052 Random eulers 4.614090291559696 ``` Comparing with higher precision (`ROTATIONS = 10000`) ``` // Simple wrap Interpolated eulers 0.8127715403175354 Random eulers 4.698880729122162 // Current wrap Interpolated eulers 0.812771551511623 Random eulers 4.698880809928011 ```

Pull request closed

Sign in to join this conversation.
No reviewers
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
2 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#104856
No description provided.