def test_intersection_with_translation(self): a = Node(name="A", parent=None) b = Node(name="B", parent=a) b.geometry = Sphere(radius=1.0) b.translate((1.0, 0.0, 0.0)) aloc = (-2.0, 0.0, 0.0) avec = (1.0, 0.0, 0.0) bloc = b.point_to_node(aloc, b) bvec = b.vector_to_node(avec, b) intersections = b.intersections(bloc, bvec) points = tuple(x.point for x in intersections) assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0))) # In local frame of b sphere is at origin intersections = a.intersections(aloc, avec) points = np.array(tuple(x.to(a).point for x in intersections)) expected = np.array(((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))) # In frame of a everything is shifed 1 along x assert np.allclose(points, expected)
def test_intersections(self): a = Node(name="A", parent=None) b = Node(name="B", parent=a) b.geometry = Sphere(radius=1.0) loc = (-1.0, 0.0, 0.0) vec = (1.0, 0.0, 0.0) intersections = b.intersections(loc, vec) points = np.array([x.point for x in intersections]) assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
def test_intersection_with_translation(self): a = Node(name="A", parent=None) b = Node(name="B", parent=a) b.geometry = Sphere(radius=1.0) b.translate((1.0, 0.0, 0.0)) aloc = (-2.0, 0.0, 0.0) avec = (1.0, 0.0, 0.0) bloc = b.point_to_node(aloc, b) bvec = b.vector_to_node(avec, b) intersections = b.intersections(bloc, bvec) points = tuple(x.point for x in intersections) assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0))) # In local frame of b sphere is at origin intersections = a.intersections(aloc, avec) points = np.array(tuple(x.to(a).point for x in intersections)) expected = np.array(((0.0, 0.0, 0.0), (2.0, 0.0, 0.0))) # In frame of a everything is shifed 1 along x assert np.allclose(points, expected)
def test_intersections(self): a = Node(name="A", parent=None) b = Node(name="B", parent=a) b.geometry = Sphere(radius=1.0) loc = (-1.0, 0.0, 0.0) vec = (1.0, 0.0, 0.0) intersections = b.intersections(loc, vec) points = np.array([x.point for x in intersections]) assert np.allclose(points, ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)))
def test_intersection_when_on_surface(self): """ Make sure we return intersection points even with zero distance from ray. """ a = Node(name="A", parent=None) a.geometry = Sphere(radius=1.0) loc = (-1.0, 0.0, 0.0) vec = (1.0, 0.0, 0.0) intersections = a.intersections(loc, vec) points = np.array([x.point for x in intersections]) expected = np.array([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)]) assert np.allclose(points, expected)
def test_intersection_when_on_surface(self): """ Make sure we return intersection points even with zero distance from ray. """ a = Node(name="A", parent=None) a.geometry = Sphere(radius=1.0) loc = (-1.0, 0.0, 0.0) vec = (1.0, 0.0, 0.0) intersections = a.intersections(loc, vec) points = np.array([x.point for x in intersections]) expected = np.array([(-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)]) assert np.allclose(points, expected)