def test_bounded_cone_bounding_box(self): shape = Cone() shape.minimum = -5 shape.maximum = 3 box = shape.bounds_of() self.assertEqual(box.min, Point(-5, -5, -5)) self.assertEqual(box.max, Point(5, 3, 5))
def test_intersect_cone_with_ray_parallel_to_half(self): shape = Cone() direction = Vector.normalize(Vector(0, 1, 1)) r = Ray(Point(0, 0, -1), direction) xs = shape.local_intersect(r) self.assertEqual(len(xs), 1) self.assertAlmostEqual(xs[0].t, 0.35355, delta=Constants.epsilon)
def test_normal_vector_on_cone(self): shape = Cone() PointNormal = namedtuple("PointNormal", ["point", "normal"]) point_normals = [ PointNormal(Point(0, 0, 0), Vector(0, 0, 0)), PointNormal(Point(1, 1, 1), Vector(1, -math.sqrt(2), 1)), PointNormal(Point(-1, -1, 0), Vector(-1, 1, 0)) ] for point_normal in point_normals: n = shape.local_normal_at(point_normal.point) self.assertEqual(n, point_normal.normal)
def test_intersect_cone_with_ray(self): shape = Cone() RayIntersection = namedtuple("RayIntersection", ["origin", "direction", "t0", "t1"]) ray_intersections = [ RayIntersection(Point(0, 0, -5), Vector(0, 0, 1), 5, 5), RayIntersection(Point(0, 0, -5), Vector(1, 1, 1), 8.66025, 8.66025), RayIntersection(Point(1, 1, -5), Vector(-0.5, -1, 1), 4.55006, 49.44994) ] for ray_intersection in ray_intersections: direction = Vector.normalize(ray_intersection.direction) r = Ray(ray_intersection.origin, direction) xs = shape.local_intersect(r) self.assertEqual(len(xs), 2) self.assertAlmostEqual(xs[0].t, ray_intersection.t0, delta=Constants.epsilon) self.assertAlmostEqual(xs[1].t, ray_intersection.t1, delta=Constants.epsilon)
def parse(self): # Load cones from file "input/cones" into a list cones = [] conesFile = open(self.filename, "r") for line in conesFile: line = line.strip().replace("\t", " ").strip("{}") if line != "": indexes = map(int, line.split()) rays = {} for i in indexes: rays[i] = self.rays[i] cone = Cone(rays) cones.append(cone) conesFile.close() return cones
def test_intersect_cone_end_cap(self): shape = Cone() shape.minimum = -0.5 shape.maximum = 0.5 shape.closed = True RayIntersection = namedtuple("RayIntersection", ["origin", "direction", "count"]) ray_intersections = [ RayIntersection(Point(0, 0, -5), Vector(0, 1, 0), 0), RayIntersection(Point(0, 0, -0.25), Vector(0, 1, 1), 2), RayIntersection(Point(0, 0, -0.25), Vector(0, 1, 0), 4) ] for ray_intersection in ray_intersections: direction = Vector.normalize(ray_intersection.direction) r = Ray(ray_intersection.origin, direction) xs = shape.local_intersect(r) self.assertEqual(len(xs), ray_intersection.count)
def detectCone(self, image, ranges): """Detects the closest cone""" distance, angle = self.rangeAnalysis(ranges) yellow = self.color[2] return Cone(self.imageAnalysis(image, yellow), image, distance, angle)
# delete small contours valid_contours = [] for con in foreground_contours: box = cv2.boundingRect(con) area = cv2.contourArea(con) if area * (-(box[1] - 1080)) > 10000: valid_contours.append(con) # calculate ratio to search the top part of a cone cones = [] for con in valid_contours: box = cv2.boundingRect(con) ratio = box[2] / box[3] if 0.6 < ratio < 0.8: detected = Cone() detected.upper_box = box detected.upper_con = con cones.append(detected) # find the bottom part of a cone delete = [] for cone in cones: min_distance = 3.5 * cone.upper_box[3] # initial distance possible_box = [0, 0, 0, 0] possible_con = [[[0]]] area_top = cv2.contourArea(cone.upper_con) for con in valid_contours: bounding_box = cv2.boundingRect(con) area_bottom = cv2.contourArea(con) # bounding box is to the left and below
def cone_sm(): """Generates a small cone.""" return Cone(point_zero(), 1, point_1_2_3())
def cone_bg(): """Generates a bigger cone.""" return Cone(point_zero(), 2, point_1_2_3())
def test_unbounded_cone_bounding_box(self): shape = Cone() box = shape.bounds_of() self.assertEqual(box.min, Point(-math.inf, -math.inf, -math.inf)) self.assertEqual(box.max, Point(math.inf, math.inf, math.inf))
# transform vertex function def transform_vert(vert, matr): tmp = vert.get_coords().dot(matr) tmp = ((tmp.dot(M) / tmp[2] + C) / 2).dot(S) return tmp # parsing JSON file with open(FILE) as json_file: data = json.load(json_file) for f in data['figures']: if f['type'] == "cones": for cone in f['params']: temp_con = Cone(cone['x'], cone['y'], cone['z'], cone['radius'], cone['height'], cone['density']) cones_arr.append(temp_con) elif f['type'] == "cylinders": for cylinder in f['params']: temp_cylin = Cylinder(cylinder['x'], cylinder['y'], cylinder['z'], \ cylinder['radius'], cylinder['height'], cylinder['density']) cyli_arr.append(temp_cylin) elif f['type'] == "cuboids": for cuboid in f['params']: temp_cuboid = Cuboid(cuboid['x'], cuboid['y'], cuboid['z'], cuboid['a'], cuboid['b'], cuboid['c']) cub_arr.append(temp_cuboid) elif f['type'] == "spheres": for sphere in f['params']: temp_sphere = Sphere(sphere['x'], sphere['y'], sphere['z'], sphere['radius'], \
raio_cone = 2 vetor_unitario_cone = Coordinate(0, 1, 0, 0) centro_base_cone1 = Coordinate(1.4142, 0, -11.3137, 1) centro_base_cone2 = Coordinate(-2.8284, 0, -15.5563, 1) # Inicializando raio e chapa raio = Ray(p0) chapa = Plate(tamanho_chapa, numero_furos_chapa, distancia_chapa) # Inicializando objetos cubo1 = Cube(centro_base_cubo1, aresta_cubo) cubo2 = Cube(centro_base_cubo2, aresta_cubo) cubo3 = Cube(centro_base_cubo3, aresta_cubo) cilindro1 = Cylinder(centro_base_cilindro1, vetor_unitario_cilindro, altura_cilindo, raio_cilindro) cone1 = Cone(centro_base_cone1, vetor_unitario_cone, altura_cone, raio_cone) cilindro2 = Cylinder(centro_base_cilindro2, vetor_unitario_cilindro, altura_cilindo, raio_cilindro) cone2 = Cone(centro_base_cone2, vetor_unitario_cone, altura_cone, raio_cone) # Colorindo objetos para facilitar identificacao cubo1.color = (46, 119, 187) cubo2.color = (29, 131, 195) cubo3.color = (39, 174, 227) imagem = Image.new('RGB', (numero_furos_chapa, numero_furos_chapa)) for l in range(chapa.number_of_holes): for c in range(chapa.number_of_holes): colisoes = [] cor_primeira_colisao = (255, 255, 255)