Repository navigation
Commit 65daaad
authored
fix: preserve small rotations in quaternion logarithms (#237)
`UnitQuaternion.Rx(1e-9).log().v` currently returns `[0, 0, 0]` instead
of `[5e-10, 0, 0]`. `acos(s / norm)` loses the angle when the quotient
rounds to one; it also loses precision for larger small rotations. Both
singleton and sequence logarithms are affected, including non-unit
quaternions.
Use `atan2(norm(v), s)` in both paths. This is the same principal angle
for a nonzero vector part, retains small-angle information, and
preserves the branch for negative scalar parts. The existing zero-vector
handling and scalar `log(norm(q))` are unchanged.
Regression tests cover signed small rotations from `1e-12` to `1e-4`
radians, an ordinary rotation, singleton/sequence agreement, non-unit
scales, `exp(log(q))`, input preservation, and the branch near the
negative real axis. The original implementation fails eight scalar
subcases, both sequence subcases, and the negative-real precision check.
Validation on Windows / Python 3.12.14:
- Complete suite: **350 passed, 3 skipped**, with all 12 new subtests
passing, on both NumPy 2.5.3 / SciPy 1.18.1 and NumPy 1.26.4 / SciPy
1.15.3 (`MPLBACKEND=Agg`, the CI timeout options).
- Independently checked 100 deterministic rotation vectors against
`scipy.spatial.transform.Rotation`, through singleton unit, singleton
scaled, and sequence unit quaternion logarithms: all **300 comparisons
pass** after the fix; 270 fail a `1e-13` relative-error check before it.
Maximum relative error after the fix is about `3.6e-16` in both
dependency environments.
- Black 23.10.0, flake8's syntax/undefined-name checks
(`E9,F63,F7,F82`), and `git diff --check` pass.
- Isolated sdist and wheel builds pass.
This validates the quaternion math and repository tests; no ROS nodes or
robot hardware were run.
---------
Co-authored-by: Jinhang Dong <186017830+dddd-jh@users.noreply.github.com>1 parent 64f4d76 commit 65daaad
2 files changed
Lines changed: 64 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
384 | 387 | | |
385 | 388 | | |
386 | 389 | | |
| |||
403 | 406 | | |
404 | 407 | | |
405 | 408 | | |
406 | | - | |
| 409 | + | |
| 410 | + | |
407 | 411 | | |
408 | 412 | | |
409 | | - | |
410 | | - | |
411 | | - | |
| 413 | + | |
412 | 414 | | |
413 | 415 | | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
943 | 943 | | |
944 | 944 | | |
945 | 945 | | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
946 | 1000 | | |
947 | 1001 | | |
948 | 1002 | | |
| |||
0 commit comments