def evaluate(param, old): #print waypoints[-1] #if sqrt(pow(param[0] - old[0], 2) + pow(param[1] - old[1], 2)) > max_distance: # return 900 verts = [(old[0], old[1]), (param[0], param[1]),] path = Path(verts, codes) for obstacle in obstacles: if sqrt(pow(param[0] - obstacle.get_xy()[0], 2) + pow(param[1] - obstacle.get_xy()[1], 2)) < 10: if path.intersects_bbox(obstacle.get_bbox()): return 900 return sqrt(pow(param[0] - 10, 2) + pow(param[1] - 10, 2))
# Fixing random state for reproducibility np.random.seed(19680801) left, bottom, width, height = (-1, -1, 2, 2) rect = plt.Rectangle((left, bottom), width, height, facecolor="#aaaaaa") fig, ax = plt.subplots() ax.add_patch(rect) bbox = Bbox.from_bounds(left, bottom, width, height) for i in range(12): vertices = (np.random.random((2, 2)) - 0.5) * 6.0 path = Path(vertices) if path.intersects_bbox(bbox): color = 'r' else: color = 'b' ax.plot(vertices[:, 0], vertices[:, 1], color=color) plt.show() def main(): pass if __name__ == '__main__': main()
from pylab import * import numpy as np from matplotlib.transforms import Bbox from matplotlib.path import Path from matplotlib.patches import Rectangle rect = Rectangle((-1, -1), 2, 2, facecolor="#aaaaaa") gca().add_patch(rect) bbox = Bbox.from_bounds(-1, -1, 2, 2) for i in range(12): vertices = (np.random.random((4, 2)) - 0.5) * 6.0 vertices = np.ma.masked_array(vertices, [[False, False], [True, True], [False, False], [False, False]]) path = Path(vertices) if path.intersects_bbox(bbox): color = 'r' else: color = 'b' plot(vertices[:,0], vertices[:,1], color=color) show()
sb = points[0][0] eb = points[1][1] print (nb, wb, sb, eb) #Size of the tasks, into how many rows and columns should the area be divided. task_cols = 40 task_rows = 30 ns_step = (sb - nb) / task_cols we_step = (eb - wb) / task_rows task_counter = 0 for row in range(task_rows): wbr = wb + row * we_step ebr = wb + (row + 1) * we_step for col in range(task_cols): nbc = nb + col * ns_step sbc = nb + (col + 1) * ns_step if islandPolygon.intersects_bbox(Bbox([[nbc, wbr], [sbc, ebr]])): boundary = 0.01 task_info = dict(question=app_config['question'], n_answers=int(args.number_answers), westbound=wbr, eastbound=ebr, northbound=nbc, southbound=sbc, westmapbound=wbr - boundary, eastmapbound=ebr + boundary, northmapbound=nbc + boundary, southmapbound=sbc - boundary, location=str(row) + "_" + str(col), batch=args.batch) response = pbclient.create_task(app_id, task_info) check_api_error(response) task_counter += 1 print(task_counter) if args.update_template: print "Updating app template" try: response = pbclient.find_app(short_name=app_config['short_name'])
for a in range(0,2): x_0 = randint(-9,9) y_0 = randint(-9,9) x_length = randint(1,10) y_length = randint(1,10) internal_rect = patches.Rectangle((x_0,y_0),x_length,y_length,linewidth=1,edgecolor='b', facecolor='none') boxes.append(internal_rect) """ f = patches.Rectangle((3,3),1,1,linewidth=1,edgecolor='b', fill = None) s = patches.Rectangle((4,4),1,1,linewidth=1,edgecolor='y', fill = None) boxes.append(f) boxes.append(s) path_f = Path(f.get_verts()) path_s = Path(s.get_verts()) pc = path_f.intersects_path(path_s, filled = True) bbc = path_f.intersects_bbox(s.get_bbox(), filled = True) print('path intersection', pc , 'bbox intersection',bbc) """ for (fi,f) in enumerate(boxes): for (si,s) in enumerate(boxes): pc = f.get_path().intersects_path(s.get_path(), filled = False) bbc = f.get_path().intersects_bbox(s.get_bbox(), filled = True) print(fi,si,'path intersection', pc , 'bbox intersection',bbc) """ for p in boxes: ax.add_patch(p) plt.show()