Пример #1
0
 def test_coodinate_system_conversions(self):
     a = Node(name='a')
     b = Node(name='b', parent=a)
     c = Node(name='c', parent=b)
     d = Node(name='d', parent=a)
     b.translate((1,1,1))
     c.translate((0,1,1))
     d.translate((-1, -1, -1))
     theta = 0.5 * np.pi
     b.rotate(theta, (0, 0, 1))
     c.rotate(theta, (1, 0, 0))
     d.rotate(theta, (0, 1, 0))
     # Points in node d to a require just travelling up the nodes.
     assert np.allclose(d.point_to_node((0, 0, 0), a), (-1, -1, -1))
     assert np.allclose(d.point_to_node((1, 1, 1), a), (0, 0, -2))
     # Directions in node d to a require just travelling up the nodes.
     assert np.allclose(d.vector_to_node((1, 0, 0), a), (0, 0, -1))
     assert np.allclose(d.vector_to_node((0, 1, 0), a), (0, 1, 0))
     assert np.allclose(d.vector_to_node((0, 0, 1), a), (1, 0, 0))
     # Points in node d to c requires going up and down nodes
     assert np.allclose(c.point_to_node((0, 0, 0), d), (-3, 2, 1))
     assert np.allclose(c.point_to_node((1, 1, 1), d), (-4, 3, 2))
     # Directions in node d to c require going up and down nodes
     assert np.allclose(c.vector_to_node((1, 0, 0), d), (0, 1, 0))
     assert np.allclose(c.vector_to_node((0, 1, 0), d), (-1, 0, 0))
     assert np.allclose(c.vector_to_node((0, 0, 1), d), (0, 0, 1))
Пример #2
0
 def test_coodinate_system_conversions(self):
     a = Node(name='a')
     b = Node(name='b', parent=a)
     c = Node(name='c', parent=b)
     d = Node(name='d', parent=a)
     b.translate((1, 1, 1))
     c.translate((0, 1, 1))
     d.translate((-1, -1, -1))
     theta = 0.5 * np.pi
     b.rotate(theta, (0, 0, 1))
     c.rotate(theta, (1, 0, 0))
     d.rotate(theta, (0, 1, 0))
     # Points in node d to a require just travelling up the nodes.
     assert np.allclose(d.point_to_node((0, 0, 0), a), (-1, -1, -1))
     assert np.allclose(d.point_to_node((1, 1, 1), a), (0, 0, -2))
     # Directions in node d to a require just travelling up the nodes.
     assert np.allclose(d.vector_to_node((1, 0, 0), a), (0, 0, -1))
     assert np.allclose(d.vector_to_node((0, 1, 0), a), (0, 1, 0))
     assert np.allclose(d.vector_to_node((0, 0, 1), a), (1, 0, 0))
     # Points in node d to c requires going up and down nodes
     assert np.allclose(c.point_to_node((0, 0, 0), d), (-3, 2, 1))
     assert np.allclose(c.point_to_node((1, 1, 1), d), (-4, 3, 2))
     # Directions in node d to c require going up and down nodes
     assert np.allclose(c.vector_to_node((1, 0, 0), d), (0, 1, 0))
     assert np.allclose(c.vector_to_node((0, 1, 0), d), (-1, 0, 0))
     assert np.allclose(c.vector_to_node((0, 0, 1), d), (0, 0, 1))
Пример #3
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)
Пример #4
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)
Пример #5
0
 def representation(self, from_node: Node, to_node: Node) -> Ray:
     """ Representation of the ray in another coordinate system.
     
     Parameters
     ----------
     from_node : Node
         The node which represents the ray's current coordinate system
     to_node : Node
         The node in which the new ray should be represented.
     
     Notes
     -----
     Use this method to express the ray location and direction as viewed in the 
     `to_node` coordinate system.
     """
     new_position = from_node.point_to_node(self.position, to_node)
     new_direction = from_node.vector_to_node(self.direction, to_node)
     new_ray = replace(self, position=new_position, direction=new_direction)
     return new_ray
Пример #6
0
 def representation(self, from_node: Node, to_node: Node) -> Ray:
     """ Representation of the ray in another coordinate system.
     
     Parameters
     ----------
     from_node : Node
         The node which represents the ray's current coordinate system
     to_node : Node
         The node in which the new ray should be represented.
     
     Notes
     -----
     Use this method to express the ray location and direction as viewed in the 
     `to_node` coordinate system.
     """
     new_position = from_node.point_to_node(self.position, to_node)
     new_direction = from_node.vector_to_node(self.direction, to_node)
     new_ray = replace(self, position=new_position, direction=new_direction)
     return new_ray