Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spatialmath/geom3d.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def LinePoint(cls, l: Line3, p: ArrayLike3) -> Self:

:seealso: :meth:`PointNormal` :meth:`ThreePoints`
"""
n = np.cross(l.w, p)
n = np.cross(l.w, p) - l.v
d = np.dot(l.v, p)

return cls(np.r_[n, d])
Expand Down
26 changes: 26 additions & 0 deletions tests/test_plane_line_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import numpy as np
import pytest

from spatialmath import Line3, Plane3


@pytest.mark.parametrize(
"anchor,direction,point",
[
([1, 2, 3], [1, 0, 0], [1, 4, 3]),
([2, -1, 4], [1, 2, -1], [3, 2, 5]),
([0, 0, 0], [0, 0, 1], [2, 3, 4]),
],
)
@pytest.mark.parametrize("scale", [1, -2, 0.25])
def test_line_point_plane_contains_translated_line(anchor, direction, point, scale):
anchor = np.asarray(anchor, dtype=float)
direction = np.asarray(direction, dtype=float) * scale
line = Line3.PointDir(anchor, direction)
plane = Plane3.LinePoint(line, np.asarray(point, dtype=float))

# Use the plane equation directly, independent of Plane3.contains.
for p in [point, anchor, anchor + direction, anchor - 3 * direction]:
np.testing.assert_allclose(plane.n @ p + plane.d, 0, atol=1e-12)
expected_normal = np.cross(direction, np.asarray(point) - anchor)
np.testing.assert_allclose(plane.n, expected_normal, atol=1e-12)