def intersect_great_circles(points, opposite_points, edges): print("points:", len(points), "edges:", len(edges), file=sys.stderr) all_points = copy.deepcopy(points) all_opposite_points = copy.deepcopy(opposite_points) circles_to_points = [] for i in range(len(edges)): print(i, file=sys.stderr) cur_points = set() for j in range(len(edges)): if j != i: points_in_cross = cross.cross(points, edges[i], edges[j]) found = False idx_found = -1 for idx in range(len(all_points)): if common.same_points(points_in_cross[0], all_points[idx]): found = True idx_found = idx break idx1, idx2 = -1, -1 if not found: idx1 = len(all_points) all_points.append(points_in_cross[0]) idx2 = len(all_points) all_points.append(points_in_cross[1]) all_opposite_points[idx1] = idx2 all_opposite_points[idx2] = idx1 else: idx1 = idx_found idx2 = all_opposite_points[idx1] cur_points.add(idx1) cur_points.add(idx2) circles_to_points.append(list(cur_points)) return all_points, all_opposite_points, circles_to_points
def add_middle_points(points, radius): dist = radius * sqrt(3) / 4 new_points = [] for i in range(len(points)): for j in range(i, len(points)): if (distance(points[i], points[j]) < dist): p3 = [points[i][0] + points[j][0], points[i][1] + points[j][1], points[i][2] + points[j][2]] if not common.same_points(p3, [0.0, 0.0, 0.0]): new_points.append(p3) return new_points
def gen_initial_great_circles(points, opposite_points, radius): dist = radius * sqrt(3) / 16 edges = set() for i in range(len(points)): print(i, file=sys.stderr) for j in range(i + 1, len(points)): if (opposite_points[i], opposite_points[j]) not in edges and (opposite_points[j], opposite_points[i]) not in edges \ and distance(points[i], points[j]) < dist: if opposite_points[i] != j: cur_normal = np.cross(points[i], points[j]) cur_normal /= distance(cur_normal, [0.0, 0.0, 0.0]) found_same_edge = False for e in edges: prev_normal = np.cross(points[e[0]], points[e[1]]) prev_normal /= distance(prev_normal, [0.0, 0.0, 0.0]) if common.same_points(cur_normal, prev_normal) or common.same_points(cur_normal, [-x for x in prev_normal]): found_same_edge = True break if not found_same_edge: edges.add((i, j)) return list(edges)
def uniq_points(points): print("before uniq points:", len(points), file=sys.stderr) for_remove = set() for i in range(len(points)): if i not in for_remove: for j in range(i + 1, len(points)): if j not in for_remove and common.same_points(points[i], points[j]): for_remove.add(j) filtered_points = [] for i in range(len(points)): if i not in for_remove: filtered_points.append(points[i]) print("after uniq points:", len(filtered_points), file=sys.stderr) return filtered_points
def add_opposite_points(points): opposite_points = dict() i = 0 while i < len(points): if i not in opposite_points: for j in range(i + 1, len(points)): if common.same_points(points[i], [-x for x in points[j]]): opposite_points[i] = j opposite_points[j] = i break if i not in opposite_points: j = len(points) points.append([-x for x in points[i]]) opposite_points[i] = j opposite_points[j] = i i += 1 return points, opposite_points