Repository navigation
Commit 824a459
angvec2r: reject a zero axis for a non-zero angle (#267)
Follow-up to #266, which makes `UnitQuaternion.AngVec` raise
`ValueError` for a non-zero angle about a zero axis. As noted there, the
base functions did not behave consistently with that.
## Problem
`angvec2r` tested the **axis** norm and returned the identity if it was
~0, whatever the angle:
```python
>>> angvec2r(0.5, [0, 0, 0]) # silently the identity
```
`angvec2tr`, `SO3.AngleAxis`/`AngVec` and `SE3.AngleAxis`/`AngVec`
inherit this. The docstring already says that `tol` is for the
"zero-rotation case" and that `V` must have finite length when the angle
is non-zero, but the code did not do that.
## Change
Test the **angle** for zero instead:
- angle zero (within `tol` eps, via `iszero`): return the identity, axis
ignored
- otherwise: normalize the axis with `unitvec`, which raises
`ValueError` for a zero-length axis
Docstring notes for `angvec2r` and `angvec2tr` updated (the old `θ ~= 0`
wording was MATLAB "not equal" and read ambiguously).
## Behaviour change
A non-zero angle about a zero-length axis (including a tiny axis below
20 eps) now raises `ValueError` rather than returning the identity.
Non-zero axes of any length are unaffected.
## Downstream
I audited the sibling toolboxes. The only affected caller is a
line-of-sight helper in RTB that applies `AngleAxis` to `cross(a, b)`,
which is zero for (anti)parallel vectors. It is already wrong for
antiparallel vectors today, and `SO3.RotatedVector` (in the released
1.1.18) is the correct replacement. Tracked in
petercorke/robotics-toolbox-python#843, to land before this is released.
## Tests
- `test_angvec2r_nonunit_axis`, `test_angvec2r_zero_axis` (rad and deg),
additions to `test_angvec2tr`, and `test_AngleAxis_zero_axis` for
`SO3`/`SE3`
- 3 of the new tests fail on current master and pass with the change;
full suite 413 passed, 3 skipped
- Not run through Black: the project pins 23.10.0 and my environment has
a newer version, so I formatted by hand and left it to pre-commit/CI
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>1 parent a0a9296 commit 824a459
3 files changed
Lines changed: 50 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
747 | 748 | | |
748 | 749 | | |
749 | 750 | | |
750 | | - | |
| 751 | + | |
751 | 752 | | |
752 | 753 | | |
753 | 754 | | |
| |||
760 | 761 | | |
761 | 762 | | |
762 | 763 | | |
763 | | - | |
764 | | - | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
765 | 768 | | |
766 | 769 | | |
767 | 770 | | |
| |||
770 | 773 | | |
771 | 774 | | |
772 | 775 | | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
778 | 781 | | |
779 | 782 | | |
780 | 783 | | |
| |||
806 | 809 | | |
807 | 810 | | |
808 | 811 | | |
809 | | - | |
810 | | - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
811 | 816 | | |
812 | 817 | | |
813 | 818 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
278 | 298 | | |
279 | 299 | | |
280 | 300 | | |
| |||
290 | 310 | | |
291 | 311 | | |
292 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
293 | 321 | | |
294 | 322 | | |
295 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
244 | 253 | | |
245 | 254 | | |
246 | 255 | | |
| |||
0 commit comments