def center_divide(road0, road1): bp0, ep0, bp1, ep1 = road0.point_list[0], road0.point_list[ -1], road1.point_list[0], road1.point_list[-1] if bp0 == bp1 or bp0 == ep1 or ep0 == bp1 or ep0 == ep1: return for i, seg0 in enumerate(road0.seg_list): for j, seg1 in enumerate(road1.seg_list): if calc_include_angle2( seg0, seg1) < math.sqrt(3) / 2 and is_segment_cross( seg0, seg1): _, px, py = get_cross_point(seg0, seg1) if px is None: print 'None' cr0 = Point(px, py) cr0.cross, cr0.cross_name, cr0.cross_other_seg = 1, road1.name, j cr0.cross_seg = i bp, ep = seg0.begin_point, seg0.end_point w0, w1 = get_dist(cr0, bp), get_dist(cr0, ep) if w0 > 1e-5 and w1 > 1e-5: road0.cross_list.append(cr0) cr1 = Point(px, py) cr1.cross, cr1.cross_name, cr1.cross_other_seg = 1, road0.name, i cr1.cross_seg = j bp, ep = seg1.begin_point, seg1.end_point w0, w1 = get_dist(cr1, bp), get_dist(cr1, ep) if w0 > 1e-5 and w1 > 1e-5: road1.cross_list.append(cr1) return
def par_divide(road0, road1): """ as center divide, divide cross point for each other :param road0: :param road1: :return: """ bp0, ep0, bp1, ep1 = road0.point_list[0], road0.point_list[ -1], road1.point_list[0], road1.point_list[-1] if bp0 == bp1: road0.bs, road1.bs = 1, 1 return elif bp0 == ep1: road0.bs, road1.es = 1, 1 return elif ep0 == bp1: road0.es, road1.bs = 1, 1 return elif ep0 == ep1: road0.es, road1.es = 1, 1 return for i, seg0 in enumerate(road0.seg_list): for j, seg1 in enumerate(road1.seg_list): if calc_include_angle2(seg0, seg1) > 0.8: # 平行 continue if is_segment_cross(seg0, seg1): _, px, py = get_cross_point(seg0, seg1) cr0 = Point(px, py) cr0.cross, cr0.cross_name, cr0.cross_other_seg = 1, road1.rid, j cr0.cross_seg = i bp, ep = seg0.begin_point, seg0.end_point w0, w1 = get_dist(cr0, bp), get_dist(cr0, ep) if w0 > 1e-5 and w1 > 1e-5: road0.cross_list.append(cr0) cr1 = Point(px, py) cr1.cross, cr1.cross_name, cr1.cross_other_seg = 1, road0.rid, i cr1.cross_seg = j bp, ep = seg1.begin_point, seg1.end_point w0, w1 = get_dist(cr1, bp), get_dist(cr1, ep) if w0 > 1e-5 and w1 > 1e-5: road1.cross_list.append(cr1) return