示例#1
0
 def test_hit_some_intersections_negative_t(self):
     s = Sphere()
     i1 = Intersection(-1, s)
     i2 = Intersection(1, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertEqual(i, i2)
示例#2
0
 def test_schlick_approximation_with_perpendicular_viewing_angle(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, 0), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-1,shape), Intersection(1, shape))
     comps = Computations.prepare_computations(xs[1], r, xs)
     reflectance = World.schlick(comps)
     self.assertAlmostEqual(reflectance, 0.04, delta = Constants.epsilon)
示例#3
0
 def test_hit_all_intersections_positive_t(self):
     s = Sphere()
     i1 = Intersection(1, s)
     i2 = Intersection(2, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertEqual(i, i1)
示例#4
0
 def intersect(self, polygon, id):
     """! Metodo de interseccion de un polygono (contorno) con el rayo
     @param polygon El objeto Polygon que representa un contorno de la simulacion.
     @param id El numero identificador del rayo al cual pertenece la interseccion.
     @return La lista de puntos de interseccion de todos los contornos que intersecta el rayo.
     """
     try:
         intersectionShape = polygon.exterior.intersection(
             self.toShapelyLine())
         centroide = self.originPoint
         if isinstance(intersectionShape, Point):
             distance = centroide.distance(intersectionShape)
             intersection = Intersection(id, intersectionShape, distance)
             self.intersectionsList.append(intersection)
         if isinstance(intersectionShape, MultiLineString):
             x, y = intersectionShape[0].xy
             point = Point(x[1], y[1])
             distance = centroide.distance(point)
             intersection = Intersection(id, point, distance)
             self.intersectionsList.append(intersection)
         if isinstance(intersectionShape, MultiPoint):
             lenMultiPoint = len(intersectionShape)
             lastPoint = intersectionShape[lenMultiPoint - 1]
             x, y = lastPoint.xy
             point = Point(x[0], y[0])
             distance = centroide.distance(point)
             intersection = Intersection(id, point, distance)
             self.intersectionsList.append(intersection)
     except:
         print("except")
     return self.intersectionsList
示例#5
0
    def intersect(self, ray):
        # transform the ray back to the sphere's object space by using the inverse of its transform matrix
        ray = self.transform.inverse().transform(ray)
        sphere_to_ray = ray.origin - self.center
        a = ray.direction.dot(ray.direction)
        b = 2 * ray.direction.dot(sphere_to_ray)
        c = sphere_to_ray.dot(sphere_to_ray) - self.radius**2
        #print(f's2r: {sphere_to_ray}')
        #print(f'ray: {ray}, sphere: {self}')
        #print(f'a: {a}, b: {b}, c: {c}')

        d = b * b - 4 * a * c
        #print(f'd: {d}')

        # test if no intersection
        if d < 0:
            return tuple()

        t1 = (-b - math.sqrt(d)) / (2 * a)
        t2 = (-b + math.sqrt(d)) / (2 * a)
        #print(f't1: {t1}, t2: {t2}')

        if t1 > t2:
            t1, t2 = t2, t1
        return (Intersection(t1, self), Intersection(t2, self))
示例#6
0
 def test_schlick_approximation_under_total_internal_reflection(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, math.sqrt(2) / 2), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-math.sqrt(2) / 2, shape), Intersection(math.sqrt(2) / 2, shape))
     comps = Computations.prepare_computations(xs[1], r, xs)
     reflectance = World.schlick(comps)
     self.assertEqual(reflectance, 1.0)
    def local_intersect_caps(self: 'Cylinder', ray: Ray,
                             xs: Iterable[Intersection], t0, t1) -> None:
        if Cylinder.check_cap(ray, t0, 1):
            xs.append(Intersection(t0, self))

        if Cylinder.check_cap(ray, t1, 1):
            xs.append(Intersection(t1, self))
示例#8
0
 def test_findinf_n1_n2_at_various_intersections(self):
     a = GlassSphere()
     a.transform = Transformations.scaling(2, 2, 2)
     a.material.refractive_index = 1.5
     b = GlassSphere()
     b.transform = Transformations.translation(0, 0, -0.25)
     b.material.refractive_index = 2.0
     c = GlassSphere()
     c.transform = Transformations.translation(0, 0, 0.25)
     c.material.refractive_index = 2.5
     r = Ray(Point(0, 0, -4), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(2, a), Intersection(2.75, b), Intersection(3.25, c), Intersection(4.75, b), Intersection(5.25, c), Intersection(6, a))
     RefractiveIndices = namedtuple("RefractiveIndices", ["n1", "n2"])
     refractive_indices_list = [
         RefractiveIndices(1.0, 1.5),
         RefractiveIndices(1.5, 2.0),
         RefractiveIndices(2.0, 2.5),
         RefractiveIndices(2.5, 2.5),
         RefractiveIndices(2.5, 1.5),
         RefractiveIndices(1.5, 1.0)
     ]
     for index, refractive_index in enumerate(refractive_indices_list):
         comps = Computations.prepare_computations(xs[index], r, xs)
         print(comps.n1)
         print(comps.n2)
         self.assertEqual(comps.n1, refractive_index.n1)
         self.assertEqual(comps.n2, refractive_index.n2)
示例#9
0
    def local_intersect_caps(self: 'Cone', ray: Ray,
                             xs: Iterable[Intersection], t0, t1) -> None:
        if Cone.check_cap(ray, t0, self.minimum):
            xs.append(Intersection(t0, self))

        if Cone.check_cap(ray, t1, self.maximum):
            xs.append(Intersection(t1, self))
示例#10
0
 def intersect(self, ray):
     intersection = None
     p = self.center - ray.origin
     dirDotP = np.dot(ray.direction, p)
     '''r_2 = self.radius**2
     inside = np.dot(p,p) < r_2
     t_c = np.dot(ray.direction,p) / magnitude(ray.direction)
     if not inside and t_c < 0:
         return None
     a = ray.origin + t_c * ray.direction - self.center
     d_2 = np.dot(a,a)
     b = r_2 - d_2
     if not inside and b <= 0:
         return None
     t_o = math.sqrt(b) / magnitude(ray.direction)
     if inside:
         return Intersection(ray, self, t_c + t_o)
     else:
         return Intersection(ray, self, t_c - t_o)'''
     diff = np.dot(p, p) - self.radius**2
     n_2 = dirDotP**2 - diff
     if n_2 >= 0:
         n = math.sqrt(n_2)
         t0 = (dirDotP - n)
         t1 = (dirDotP + n)
         #if diff < 0: # if inside sphere
         #    intersection = Intersection(ray, self, t1)
         if t0 < t1:
             intersection = Intersection(ray, self, t0)
         else:
             intersection = Intersection(ray, self, t1)
     return intersection
示例#11
0
    def test_hit(self):
        # test hit with positive t
        s = Sphere()
        i1 = Intersection(1, s)
        i2 = Intersection(2, s)
        xs = (i1, i2)
        h = hit(xs)
        self.assertEqual(h, i1)

        # test hit with some negative t intersections
        i1 = Intersection(-1, s)
        i2 = Intersection(1, s)
        xs = (i1, i2)
        h = hit(xs)
        self.assertEqual(h, i2)

        # test hit with all negative t intersections
        i1 = Intersection(-2, s)
        i2 = Intersection(-1, s)
        xs = (i1, i2)
        h = hit(xs)
        self.assertIsNone(h)

        # test hit is lowest non-negative t value
        i1 = Intersection(5, s)
        i2 = Intersection(7, s)
        i3 = Intersection(-3, s)
        i4 = Intersection(2, s)
        xs = (i1, i2, i3, i4)
        h = hit(xs)
        self.assertEqual(h, i4)
示例#12
0
 def test_hit_all_intersections_negative_t(self):
     s = Sphere()
     i1 = Intersection(-2, s)
     i2 = Intersection(-1, s)
     xs = Intersection.intersections(i2, i1)
     i = Intersection.hit(xs)
     self.assertIsNone(i)
示例#13
0
 def test_schlick_approximation_with_small_angle(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0.99, -2), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(1.8589, shape))
     comps = Computations.prepare_computations(xs[0], r, xs)
     reflectance = World.schlick(comps)
     self.assertAlmostEqual(reflectance, 0.48873, delta = Constants.epsilon)
示例#14
0
 def test_aggregate_intersections(self):
     s = Sphere()
     i1 = Intersection(1, s)
     i2 = Intersection(2, s)
     xs = Intersection.intersections(i1, i2)
     self.assertEqual(len(xs), 2)
     self.assertEqual(xs[0].t, 1)
     self.assertEqual(xs[1].t, 2)
示例#15
0
    def __init__(self):
        """Initialize"""
        self.dataStorage = DataLogging()
        """Initialize PyGame"""
        pygame.init()
        """Set the window Size"""
        self.width = WIDTH
        self.height = HEIGHT
        """Create the Screen"""
        self.screen = pygame.display.set_mode((self.width, self.height))
        pygame.display.set_caption('Traffic Control Simulation')
        # Initialize font
        self.font = pygame.font.SysFont('monospace', 14)

        # Define vehicles to be used
        self.vehicles = [VehicleCar, VehicleTruck]
        self.intersection = Intersection(
            center=Coord(x=WIDTH * 0.5, y=HEIGHT * 0.5))
        # Add traffic light
        traffic_lightWE = TrafficLight(strategy='classic', id_=0)
        traffic_lightEW = TrafficLight(strategy='classic', id_=1)
        traffic_lightSN = TrafficLight(strategy='classic', id_=2)
        traffic_lightNS = TrafficLight(strategy='classic', id_=3)
        # Add a few dummy lanes
        self.intersection.add_lane(direction=Coord(1, 0),
                                   towards=False,
                                   order=0)  #0
        self.intersection.add_lane(direction=Coord(1, 0),
                                   towards=True,
                                   order=0,
                                   light=traffic_lightWE)  #1
        self.intersection.add_lane(direction=Coord(-1, 0),
                                   towards=True,
                                   order=0,
                                   light=traffic_lightEW)  #2
        self.intersection.add_lane(direction=Coord(-1, 0),
                                   towards=False,
                                   order=0)  #3
        self.intersection.add_lane(direction=Coord(0, -1),
                                   towards=False,
                                   order=0)  #4
        self.intersection.add_lane(direction=Coord(0, -1),
                                   towards=True,
                                   order=0,
                                   light=traffic_lightSN)  #5
        self.intersection.add_lane(direction=Coord(0, 1),
                                   towards=False,
                                   order=0)  #6
        self.intersection.add_lane(direction=Coord(0, 1),
                                   towards=True,
                                   order=0,
                                   light=traffic_lightNS)  #7

        self.controller = Controller(self.intersection.get_lanes())

        self.frame_timing = pygame.time.Clock()
        self.carframecounter = 0
        self.total_frames = 0
示例#16
0
 def test_under_point_offset_below_surface(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = GlassSphere()
     shape.transform = Transformations.translation(0, 0, 1)
     i = Intersection(5, shape)
     xs = Intersection.intersections(i)
     comps = Computations.prepare_computations(i, r, xs)
     self.assertGreater(comps.under_point.z, Constants.epsilon / 2)
     self.assertLess(comps.point.z, comps.under_point.z)
示例#17
0
 def test_refracted_color_with_opaque_surface(self):
     w = World.default_world()
     shape = w.objects[0]
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(4, shape),
                                     Intersection(6, shape))
     comps = Computations.prepare_computations(xs[0], r, xs)
     c = World.refracted_color(w, comps, 5)
     self.assertEqual(c, Color(0, 0, 0))
示例#18
0
 def test_refracted_color_at_max_recursive_depth(self):
     w = World.default_world()
     shape = w.objects[0]
     shape.material.transparency = 1.0
     shape.material.refractive_index = 1.5
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(4, shape),
                                     Intersection(6, shape))
     comps = Computations.prepare_computations(xs[0], r, xs)
     c = World.refracted_color(w, comps, 0)
     self.assertEqual(c, Color(0, 0, 0))
示例#19
0
    def local_intersect(self, ray: Ray) -> Iterable[Intersection]:
        xtmin, xtmax = Cube.check_axis(ray.origin.x, ray.direction.x)
        ytmin, ytmax = Cube.check_axis(ray.origin.y, ray.direction.y)
        ztmin, ztmax = Cube.check_axis(ray.origin.z, ray.direction.z)

        tmin = max([xtmin, ytmin, ztmin])
        tmax = min([xtmax, ytmax, ztmax])

        if tmin > tmax:
            return []

        return [Intersection(tmin, self), Intersection(tmax, self)]
示例#20
0
    def __init__(self, x, y, road, length_along_road, master, car_images,
                       car_size, spawn_delay=2.0, cars=[], generative=False):
        Intersection.__init__(self, x, y, incoming_roads=[])
        self.road = road
        self.length_along_road = length_along_road
        self.cars = set(cars)
        self.generative = generative

        # set up the car spawning thread
        source_thread = threading.Thread(target=self.spawn_loop,
                        args=[master, car_images, car_size, spawn_delay])
        source_thread.daemon = True
        source_thread.start()
示例#21
0
 def test_refracted_color_under_total_internal_reflection(self):
     w = World.default_world()
     shape = w.objects[0]
     shape.material.transparency = 1.0
     shape.material.refractive_index = 1.5
     r = Ray(Point(0, 0, math.sqrt(2) / 2), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-math.sqrt(2) / 2, shape),
                                     Intersection(math.sqrt(2) / 2, shape))
     # NOTE: this time you're inside the sphere, so you need
     # to look at the second intersection, xs[1], not xs[0]
     comps = Computations.prepare_computations(xs[1], r, xs)
     c = World.refracted_color(w, comps, 5)
     self.assertEqual(c, Color(0, 0, 0))
示例#22
0
    def ell(self, scene, ray, camera):
        intersection = Intersection(np.array([0., 0., 0.]),
                                    np.array([0., 1., 0.]))
        intersection.color = np.array([1., 1., 1.])
        if (scene.intersect(ray, intersection)):
            return np.max([
                0.0,
                np.min([
                    1.0,
                    intersection.ell + MonteCarlo(intersection, scene, 256)
                ])
            ]) * intersection.color

        return np.array([0., 0., 0.])
示例#23
0
    def local_intersect(self, ray: Ray) -> Iterable[Intersection]:
        sphere_to_ray = ray.origin - Point(0, 0, 0)
        a = Vector.dot(ray.direction, ray.direction)
        b = 2 * Vector.dot(ray.direction, sphere_to_ray)
        c = Vector.dot(sphere_to_ray, sphere_to_ray) - 1
        discriminant = b**2 - 4 * a * c

        if discriminant < 0:
            return Intersection.intersections()

        t1 = (-b - math.sqrt(discriminant)) / (2 * a)
        t2 = (-b + math.sqrt(discriminant)) / (2 * a)

        return Intersection.intersections(Intersection(t1, self),
                                          Intersection(t2, self))
示例#24
0
 def test_filtering_list_intersections(self):
     s1 = Sphere()
     s2 = Cube()
     Operation = namedtuple("Operation", ["operation", "x0", "x1"])
     operatios = [
         Operation("union", 0, 3),
         Operation("intersection", 1, 2),
         Operation("difference", 0, 1)
     ]
     for operation in operatios:
         c = CSG(operation.operation, s1, s2)
         xs = Intersection.intersections(Intersection(1, s1), Intersection(2, s2), Intersection(3, s1), Intersection(4, s2))
         result = c.filter_intersections(xs)
         self.assertEqual(len(result), 2)
         self.assertEqual(result[0], xs[operation.x0])
         self.assertEqual(result[1], xs[operation.x1])
示例#25
0
    def set_intersections(self, G):
        """
        Method: set_intersections

        Method Arguments:
        * G - The graph of a real section of the world that will be produced
              from using the osmnx package and the lat and lon provided by the
              user input.

        Output:
        * A dictionary of the nodes created will be returned, where each node id
          is their key.
        """

        node_dict = {}
        for n in G.nodes(data=True):
            name = n[1]['osmid']
            x = n[1]['x']
            y = n[1]['y']
            node_to_insert = Intersection(name, x, y, self)
            if name in node_dict:
                #print("duplicate")
                pass
            else:
                node_dict[name] = node_to_insert
        return node_dict
    def set_intersections(self, G):
        """
        Method: set_intersections

        Method Arguments:
        * G - The graph of a real section of the world that will be produced
              from using the osmnx package and the lat and lon provided by the
              user input.

        Output:
        * A dictionary of the nodes created will be returned, where each node id
          is their key.
        """ 
        node_dict = {}
        g_nodes = G.nodes()
        for n in g_nodes.keys():
            name = g_nodes[n]['osmid']
            x = g_nodes[n]['x'] # -122
            y = g_nodes[n]['y'] # 42
            zipcode = get_zip(y,x) #Insert point for zipcode data

            weight = get_pop(zipcode)
                
            node_to_insert = Intersection(name, x, y, weight, zipcode, self)
            if name in node_dict: #If the name's not in the dictionary, put the node in the dictionary
                #print("duplicate")
                pass
            else:
                node_dict[name] = node_to_insert #Insert Node
        return node_dict #Return full dictionary with data added. 
    def FillCacheComplete(self, camera, scene):
        print("\033[32mInfo\033[30m: Fill cache Completely")
        print("\033[32mInfo\033[30m: Initial fill")
        self.fillCache(camera, scene)
        print("\033[32mInfo\033[30m: Initial fill complete")
        print("\033[32mInfo\033[30m: Begin the complete fill")
        s = time.perf_counter()
        for i in range(camera.image.shape[0]):
            print("\033[32mInfo\033[30m:\033[36m",
                  int(10000 * i / camera.image.shape[0]) / 100,
                  "\033[30m% of the cache is filled")
            for j in range(camera.image.shape[1]):
                r = camera.generateRay(i, j)
                intersection = Intersection()

                if scene.intersect(r, intersection):
                    for k in range(self.maxBounceDepth, 0, -1):
                        interpolatedPoint = Irradiance_ProcessData(
                            intersection.pos, intersection.n, self.minWeight,
                            self.maxCosAngleDiff)
                        interpval = self.getInterpolatedValue(
                            interpolatedPoint, k)

                        if (interpval < 0).any():
                            self.generateSample(intersection, scene, camera, r,
                                                k)

        e = time.perf_counter()
        seconds = e - s
        m = int(seconds / 60)
        seconds = seconds % 60
        h = int(m / 60)
        m = m % 60
        print("\033[32mInfo\033[30m: completely filling the cache took", h,
              ":", m, ":", seconds)
    def fillCache(self, camera, scene):
        pix_x = camera.image.shape[0]
        pix_y = camera.image.shape[1]

        print(pix_x)
        print(pix_y)
        print(self.maxPixelDist)

        if (self.parallel):
            p = Pool(8)
            A = [(x, y, scene, camera)
                 for x in range(0, pix_x, self.maxPixelDist)
                 for y in range(0, pix_y, self.maxPixelDist)]
            p.map(self.fillCachParallelHelp, A)
        else:
            for i in range(0, pix_x, self.maxPixelDist):
                print(
                    "Filling Cache :",
                    int(10000 * (i / self.maxPixelDist) /
                        (int(pix_x / self.maxPixelDist) + 1)) / 100, "%")
                for j in range(0, pix_y, self.maxPixelDist):
                    print(i, " ", j)
                    ray = camera.generateRay(i, j)
                    intersection = Intersection()
                    if (scene.intersect(ray, intersection)):
                        s = self.generateSample(intersection, scene, camera,
                                                ray, self.maxBounceDepth)
示例#29
0
 def test_refracted_color_with_refracted_ray(self):
     w = World.default_world()
     a = w.objects[0]
     a.material.ambient = 1.0
     a.material.pattern = Pattern.test_pattern()
     b = w.objects[1]
     b.material.transparency = 1.0
     b.material.refractive_index = 1.5
     r = Ray(Point(0, 0, 0.1), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-0.9899, a),
                                     Intersection(-0.4899, b),
                                     Intersection(0.4899, b),
                                     Intersection(0.9899, a))
     comps = Computations.prepare_computations(xs[2], r, xs)
     c = World.refracted_color(w, comps, 5)
     self.assertEqual(c, Color(0, 0.99888, 0.04725))
示例#30
0
def intersectSphere(origin, ray, sphere):

    center = np.array(sphere["center"])
    radius = float(sphere["radius"])

    closestIntersect = Intersection.worstCase()

    a = np.dot(ray, ray)
    b = np.dot(2*ray, (origin - center))
    c = np.dot((origin - center), (origin - center)) - (radius * radius)

    delta = b*b - 4*a*c
    if(delta > 0):

        t1 = (-b - math.sqrt(delta)) / (2*a)
        t2 = (-b + math.sqrt(delta)) / (2*a)
        ti = min(t1, t2)

        if(ti > 0):

            pi = origin + ray*ti
            n = (pi - center)
            n /= np.linalg.norm(n)

            return Intersection(ti, n, pi, sphere)

    return None
示例#31
0
 def createMiddleRing(self):
     self.intersections.append(Intersection(0, 1, [[1,1],[7,1]]))
     self.intersections.append(Intersection(1, 1, [[0,1],[2,1],[1,0],[1,2]]))
     self.intersections.append(Intersection(2, 1, [[1,1],[3,1]]))
     self.intersections.append(Intersection(3, 1, [[2,1],[4,1],[3,0],[3,2]]))
     self.intersections.append(Intersection(4, 1, [[3,1],[5,1]]))
     self.intersections.append(Intersection(5, 1, [[4,1],[6,1],[5,0],[5,2]]))
     self.intersections.append(Intersection(6, 1, [[5,1],[7,1]]))
     self.intersections.append(Intersection(7, 1, [[0,1],[6,1],[7,0],[7,2]]))
示例#32
0
 def createRing(self, ring):
     self.intersections.append(Intersection(0, ring, [[1,ring],[7,ring]]))
     self.intersections.append(Intersection(1, ring, [[0,ring],[2,ring],[1,1]]))
     self.intersections.append(Intersection(2, ring, [[1,ring],[3,ring]]))
     self.intersections.append(Intersection(3, ring, [[2,ring],[4,ring],[3,1]]))
     self.intersections.append(Intersection(4, ring, [[3,ring],[5,ring]]))
     self.intersections.append(Intersection(5, ring, [[4,ring],[6,ring],[5,1]]))
     self.intersections.append(Intersection(6, ring, [[5,ring],[7,ring]]))
     self.intersections.append(Intersection(7, ring, [[0,ring],[6,ring],[7,1]]))
示例#33
0
 def __init__(self, x, y, destructive=False):
     Intersection.__init__(self, x, y, outgoing_roads=[], incoming_roads=[])
     self.destructive = destructive
     self.cars = set()
示例#34
0
def intersectCube(origin, ray, cube):

    minBound = np.array(cube["min"])
    maxBound = np.array(cube["max"])

    closestIntersect = Intersection.worstCase()

    # Front side
    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], minBound[1], minBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], minBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], maxBound[1], minBound[2]])
    p3 = np.array([minBound[0], maxBound[1], minBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    # Back side
    p1 = np.array([minBound[0], minBound[1], maxBound[2]])
    p2 = np.array([minBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([minBound[0], minBound[1], maxBound[2]])
    p2 = np.array([minBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    # Right side
    p1 = np.array([maxBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], maxBound[1], minBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([maxBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([maxBound[0], minBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    # Left side
    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([minBound[0], maxBound[1], minBound[2]])
    p3 = np.array([minBound[0], maxBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([minBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([minBound[0], maxBound[1], minBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection
    
    # Up side
    p1 = np.array([minBound[0], maxBound[1], minBound[2]])
    p2 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], minBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([minBound[0], maxBound[1], minBound[2]])
    p2 = np.array([minBound[0], maxBound[1], maxBound[2]])
    p3 = np.array([maxBound[0], maxBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    # Down side
    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], minBound[1], minBound[2]])
    p3 = np.array([maxBound[0], minBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    p1 = np.array([minBound[0], minBound[1], minBound[2]])
    p2 = np.array([maxBound[0], minBound[1], maxBound[2]])
    p3 = np.array([minBound[0], minBound[1], maxBound[2]])
    intersection = intersectTriangle(p1, p2, p3, origin, ray)
    if(intersection != None and intersection < closestIntersect):
        intersection.obj = cube
        closestIntersect = intersection

    if(closestIntersect.distance < 1000):
        return closestIntersect

    return None