Repository navigation
Commit 61a6c4f
authored
Fix Line3 distance for parallel and non-unit directions (#224)
`Line3.distance()` raises `NameError` for parallel lines and can return
incorrect distances for skew or intersecting lines. For example:
```python
from spatialmath import Line3
a = Line3.PointDir([0, 0, 0], [1, 0, 0])
b = Line3.PointDir([0, 0, 2], [0.6, 0.8, 0])
print(a.distance(b)) # before: 2.5; expected: 2.0
```
The old expression divides by the squared cross-product norm and uses a
reciprocal product that mixes unit directions with unnormalized moments.
Scaling directions can therefore change the result; a translated
intersecting pair can also return a nonzero distance.
Compute the displacement between principal points and project it onto
the common normal of the unit directions. For parallel directions, use
the perpendicular component of that displacement and return a scalar.
Apply the existing `tol` parameter to the parallel-direction test.
Initial validation on base `f6a572c6e75e2a7e3c06e632bc34153941e00404`:
- Added regressions with the original implementation: **21 failed, 18
passed** in `tests/test_geom3d.py`; with the fix: **39 passed**.
- Full `tests` suite: baseline **346 passed, 3 skipped**; fixed **367
passed, 3 skipped**, on Python 3.10/NumPy 2.2.6 and Python 3.12/NumPy
2.5.3. Existing plotting/deprecation warnings remain.
- Separate seeded validation: **4,800 scalar comparisons per
environment** against closest points computed by `numpy.linalg.lstsq`,
including parallel/intersecting/skew lines, sign/scale changes, rigid
transformations and operand reversal.
- Pinned pre-commit hooks on both changed files, `git diff --check`,
wheel and sdist builds passed.
The branch is now rebased onto upstream `2de7801` (current head
`9600087`). On this updated tree, the complete `tests` suite passes with
**368 passed, 3 skipped** on Python 3.10.12, and the four pre-commit
hooks on both changed files and `git diff --check` pass. The newer
upstream commit adds a separate spatial-vector regression, accounting
for one more passing test than the initial run. GitHub Actions has since
run: all **10 platform/Python unittest jobs**, the aggregate test check,
and Codecov passed. The Sphinx documentation build succeeded with 22
warnings, but its final `gh-pages` push failed with HTTP 403 because
`github-actions[bot]` lacks write permission for this fork PR. This
patch changes only `spatialmath/geom3d.py` and `tests/test_geom3d.py`.
AI assistance: the implementation, tests and this description were
prepared with Codex; the local validation commands were executed
locally, and the multi-platform results above come from GitHub Actions.1 parent 3899801 commit 61a6c4f
2 files changed
Lines changed: 41 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
839 | | - | |
| 839 | + | |
840 | 840 | | |
841 | 841 | | |
842 | 842 | | |
| |||
847 | 847 | | |
848 | 848 | | |
849 | 849 | | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
864 | 860 | | |
865 | 861 | | |
866 | 862 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
20 | 50 | | |
21 | 51 | | |
22 | 52 | | |
| |||
0 commit comments