示例#1
0
 def test_close_to_zero(self):
     # Value is considered zero if abs(value) < EPS_ZERO
     zero = 0.0
     assert close_to_zero(zero) == True
     assert close_to_zero(zero + 0.9 * EPS_ZERO) == True
     assert close_to_zero(zero - 0.9 * EPS_ZERO) == True
     assert close_to_zero(zero + EPS_ZERO) == False
     assert close_to_zero(zero - EPS_ZERO) == False
示例#2
0
 def is_on_surface(self, point):
     # Just use any direction for a fake ray, we only need the distance
     _, dist = ray_z_cylinder(self.length, self.radius, point, norm((1, 1, 1)))
     if len(dist) == 0:
         return False
     dist = dist[0]  # Only need closest intersection
     if close_to_zero(dist):
         # print("dist from point {} {} is_on_surface True".format(dist, point))
         return True
     # print("dist from point {} {} is_on_surface False".format(dist, point))
     return False
示例#3
0
 def is_on_surface(self, point):
     # Just use any direction for a fake ray, we only need the distance
     _, dist = ray_z_cylinder(self.length, self.radius, point, norm((1,1,1)))
     if len(dist) == 0:
         return False
     dist = dist[0]  # Only need closest intersection
     if close_to_zero(dist):
         print("dist from point {} {} is_on_surface True".format(dist, point))
         return True
     print("dist from point {} {} is_on_surface False".format(dist, point))
     return False
示例#4
0
def next_hit(scene, ray):
    """ Returns information about the next interface the ray makes with the scene.
    
        Parameters
        ----------
        scene : Scene
        ray : Ray
    
        Returns
        -------
        hit_node : Node
            The node corresponding to the geometry object that was hit.
        interface : tuple of Node
            Two node: the `container` and the `adjacent` which correspond to the
            materials either side of the interface.
        point: tuple of float
            The intersection point.
        distance: float
            Distance to the intersection point.
    """
    # Intersections are in the local node's coordinate system
    intersections = scene.intersections(ray.position, ray.direction)

    # Remove on surface intersections
    intersections = \
        [x for x in intersections if not close_to_zero(x.distance)]

    # Convert intersection points to world node
    intersections = [x.to(scene.root) for x in intersections]

    # Node which owns the surface
    if len(intersections) == 0:
        return None

    # The surface being hit
    hit = intersections[0]
    if len(intersections) == 1:
        hit_node = hit.hit
        return hit_node, (hit_node, None), hit.point, hit.distance

    container = find_container(intersections)
    hit = intersections[0]
    # Intersection point and distance from ray
    point = hit.point
    hit_node = hit.hit
    distance = distance_between(ray.position, point)
    if container == hit_node:
        adjacent = intersections[1].hit
    else:
        adjacent = hit_node
    return hit_node, (container, adjacent), point, distance