Skip to content

fix: retain the correct axis for small matrix rotations - #81

Open
h55n wants to merge 1 commit into
matthew-brett:mainfrom
h55n:fix/small-matrix-axis-angle
Open

h55n wants to merge 1 commit into
matthew-brett:mainfrom
h55n:fix/small-matrix-axis-angle

Conversation

@h55n

@h55n h55n commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #79.

For a rotation below unit_thresh, the complex conjugate eigenvalues can be close enough to one to pass the unit-eigenvalue check. Selecting the last passing eigenvector can then return a vector unrelated to the rotation axis, with the wrong norm and angle.

Select the eigenvalue closest to one instead. Keep the last eigenvector on exact ties so identity/scaled-identity behavior stays unchanged, and preserve the existing strict threshold check, including zero, negative and NaN thresholds. Angle calculation and the public API are unchanged.

Tests cover small positive and negative rotations, two thresholds, unit axis length, signed rotation vectors, matrix reconstruction and threshold edge cases. The small-rotation regression fails on unchanged main. Existing identity, large-angle and invalid-matrix tests remain unchanged.

Validation:

  • Local full package tests and doctests: 93 passed. Wheel/sdist build and git diff --check pass.
  • Independent check: 9,000 rotation reconstructions, including small angles, zero and pi; maximum matrix error below 3.2e-13.
  • Full fork matrix: Python 3.7 through 3.12 plus the original Python 3.7 / NumPy 1.15 minimum-dependency job each pass all 93 tests and coverage generation: https://github.com/h55n/transforms3d/actions/runs/43210536990

The proof workflow pins Ubuntu 22.04 for the older interpreters, disables fail-fast and skips only the token-protected Codecov upload. All original dependency specifications and test/coverage commands are retained. Source/test blobs match this branch exactly; no workflow change is included here.

The first proof attempt failed in the unchanged test_ref_aff2sadn shear-reference test on Python 3.12. It does not call mat2axangle; the test itself notes its numerical instability. The complete unchanged baseline matrix passed, and the complete candidate matrix passed on rerun. No test, dependency or tolerance was changed to obtain the passing result.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mat2axangle returns a wrong axis and angle for rotations smaller than unit_thresh

1 participant