From f82fb79e6b3520cb7340b8701af12596cbce1891 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Mon, 30 Sep 2019 16:27:11 -0400 Subject: [PATCH] Plane.line_xsections: Document the behavior in a degenerate case --- polliwog/plane/plane.py | 1 + polliwog/plane/test_plane.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/polliwog/plane/plane.py b/polliwog/plane/plane.py index 0c99d97..089b97d 100644 --- a/polliwog/plane/plane.py +++ b/polliwog/plane/plane.py @@ -248,6 +248,7 @@ def _line_segment_xsection(self, a, b): def line_xsections(self, pts, rays): k = vg.shape.check(locals(), "pts", (-1, 3)) vg.shape.check(locals(), "rays", (k, 3)) + denoms = np.dot(rays, self.normal) denom_is_zero = denoms == 0 denoms[denom_is_zero] = np.nan diff --git a/polliwog/plane/test_plane.py b/polliwog/plane/test_plane.py index 8e31463..19549aa 100644 --- a/polliwog/plane/test_plane.py +++ b/polliwog/plane/test_plane.py @@ -299,6 +299,26 @@ def test_line_plane_intersections(): np.testing.assert_array_equal(is_intersecting, [False, False, True, True]) +def test_line_plane_intersections_coplanar_input(): + # TODO Intersecting the x-z plane with a line that lies in the x-z plane + # returns non-intersecting. Is this desirable? + + # x-z plane + normal = np.array([0.0, 1.0, 0.0]) + sample = np.array([0.0, 0.0, 0.0]) + + plane = Plane(sample, normal) + + # A line that lies in the x-z plane. + pts = np.array([[1.0, 0.0, -1.0]]) + rays = np.array([[1.0, 0.0, 2.0]]) + + expected = np.array([[np.nan, np.nan, np.nan]]) + intersections, is_intersecting = plane.line_xsections(pts, rays) + np.testing.assert_array_equal(intersections, expected) + np.testing.assert_array_equal(is_intersecting, [False]) + + def test_line_segment_plane_intersection(): # x-z plane normal = np.array([0.0, 1.0, 0.0])