diff --git a/polliwog/plane/plane.py b/polliwog/plane/plane.py index 0c99d975..089b97d3 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 8e314632..19549aae 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])