def exhaustive(points, show=True, save=False, detailed=False): """ Returns the vertices comprising the boundaries of convex hull containing all points in the input set. The input 'points' is a list of [x,y] coordinates. Uses a very naive method: iterates over the whole set of convex polygons from size 3 to n :param points: the points from which to find the convex hull :param show: if True, the progress in constructing the hull will be plotted on each iteration in a window :param save: if True, the progress in constructing the hull will be saved on each iteration in a .png file :param detailed: if True, even non convex explored polygons are plotted :return: the convex hull """ i = 3 while i <= len(points): # iterates over the whole set of subset of points for subset in permutations(points, i): #if (show or save) and detailed: #scatter_plot(points, [subset], title="exhaustive search", show=show, save=save) # only consider convex subsets if is_convex(subset): #if (show or save) and not detailed: #scatter_plot(points, [subset], title="exhaustive search", show=show, save=save) one_out = False j = 0 # iterates until a point is found outside the polygon while not one_out and j < len(points): point = points[j] if point not in list(subset) and not point_in_polygon( point, list(subset)): one_out = True j = j + 1 if not one_out: return subset i = i + 1 return points
def import_dxf_example(): dxf_filepath = os.path.join(os.getcwd(), 'example_files', 'section_holes_complex.dxf') my_dxf = dxf.DxfImporter(dxf_filepath) my_dxf.process() my_dxf.cleanup() polygons = my_dxf.polygons for p in polygons: x, y = p.exterior.xy new = utils.find_holes(polygons) x, y = new.exterior.xy plt.plot(x, y) for hole in new.interiors: x, y = hole.xy plt.plot(x, y) for i in range(100): p = utils.point_in_polygon(new) x, y = p.xy plt.plot(x, y, marker='o', markersize=3, color="red") plt.show()
def __fitness_obstacles(self, subject, mapa): # Prioriza rotas que não ultrapassem obstáculos # Não bater em obstáculos count = 0 for gene_decoded_t1, gene_decoded_t2 in pairwise_circle(subject.dna_decoded): for area_n in mapa.areas_n: wp1 = CartesianPoint(gene_decoded_t1.x, gene_decoded_t1.y) if point_in_polygon(wp1, area_n): count += 1 wp2 = CartesianPoint(gene_decoded_t2.x, gene_decoded_t2.y) if segment_in_polygon(wp1, wp2, area_n): count += 1 return count
def __fitness_obstacles(self, subject, mapa): # Prioriza rotas que não ultrapassem obstáculos count = 0 for gene_decoded_t1, gene_decoded_t2 in pairwise(subject.dna_decoded): # Utiliza somente as áreas infladas para cálculo for area_n in mapa.areas_n_inf: wp1 = CartesianPoint(gene_decoded_t1.x, gene_decoded_t1.y) wp2 = CartesianPoint(gene_decoded_t2.x, gene_decoded_t2.y) # Calcula se algum waypoint está dentro de algum obstáculo if point_in_polygon(wp1, area_n): count += 1 # Calcula se alguma conexão entre os waypoints intersecciona algum obstáculo if segment_in_polygon(wp1, wp2, area_n): count += 1 return count