|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +from spatialmath import Line3, Plane3 |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + "anchor,direction,point", |
| 9 | + [ |
| 10 | + ([1, 2, 3], [1, 0, 0], [1, 4, 3]), |
| 11 | + ([2, -1, 4], [1, 2, -1], [3, 2, 5]), |
| 12 | + ([0, 0, 0], [0, 0, 1], [2, 3, 4]), |
| 13 | + ], |
| 14 | +) |
| 15 | +@pytest.mark.parametrize("scale", [1, -2, 0.25]) |
| 16 | +def test_line_point_plane_contains_translated_line(anchor, direction, point, scale): |
| 17 | + anchor = np.asarray(anchor, dtype=float) |
| 18 | + direction = np.asarray(direction, dtype=float) * scale |
| 19 | + line = Line3.PointDir(anchor, direction) |
| 20 | + plane = Plane3.LinePoint(line, np.asarray(point, dtype=float)) |
| 21 | + |
| 22 | + # Use the plane equation directly, independent of Plane3.contains. |
| 23 | + for p in [point, anchor, anchor + direction, anchor - 3 * direction]: |
| 24 | + np.testing.assert_allclose(plane.n @ p + plane.d, 0, atol=1e-12) |
| 25 | + expected_normal = np.cross(direction, np.asarray(point) - anchor) |
| 26 | + np.testing.assert_allclose(plane.n, expected_normal, atol=1e-12) |
0 commit comments