Пример #1
0
def gen_noncrossing_edges(query_edges, boundary_edges, allpoints):
    """
    Yield query edges which do not intersect boundary edges.
    @param query_edges: point index pairs
    @param boundary_edges: point index pairs
    @param allpoints: ordered points as pairs of coordinates
    """
    for query in query_edges:
        q0 = CompGeom.Point(allpoints[query[0]])
        q1 = CompGeom.Point(allpoints[query[1]])
        for boundary in boundary_edges:
            b0 = CompGeom.Point(allpoints[boundary[0]])
            b1 = CompGeom.Point(allpoints[boundary[1]])
            if CompGeom.line_segments_intersect(q0, q1, b0, b1):
                break
        else:
            yield query
Пример #2
0
def get_intersecting_edges(points, edges):
    """
    Edges that share an endpoint do not count as conflicting.
    @param points: a list of numpy arrays each of length 2
    @param edges: a list of point index pairs
    @return: the set of edges that intersect at least one other edge
    """
    conflicts = set()
    sedgewick_points = [CompGeom.Point(p.tolist()) for p in points]
    for ea, eb in itertools.combinations(edges, 2):
        # only check intersection when each endpoint is unique
        if len(set([ea[0], ea[1], eb[0], eb[1]])) == 4:
            a = sedgewick_points[ea[0]]
            b = sedgewick_points[ea[1]]
            c = sedgewick_points[eb[0]]
            d = sedgewick_points[eb[1]]
            if CompGeom.line_segments_intersect(a, b, c, d):
                conflicts.add(ea)
                conflicts.add(eb)
    return conflicts
Пример #3
0
def gen_noncrossing_edges(query_edges, boundary_edges, allpoints):
    """
    Yield query edges which do not intersect boundary edges.
    @param query_edges: point index pairs
    @param boundary_edges: point index pairs
    @param allpoints: ordered points as pairs of coordinates
    """
    for query in query_edges:
        q0 = CompGeom.Point(allpoints[query[0]])
        q1 = CompGeom.Point(allpoints[query[1]])
        for boundary in boundary_edges:
            b0 = CompGeom.Point(allpoints[boundary[0]])
            b1 = CompGeom.Point(allpoints[boundary[1]])
            if CompGeom.line_segments_intersect(q0, q1, b0, b1):
                break
        else:
            yield query
Пример #4
0
def sample_with_rejection(npoints, poly, limit):
    """
    @param npoints: sample this many points with rejection
    @param poly: reject points outside the polygon
    @param limit: a sanity limit for rejection sampling
    @return: the sampled points
    """
    xpoly, ypoly = zip(*poly)
    xlow, xhigh = min(xpoly), max(xpoly)
    ylow, yhigh = min(ypoly), max(ypoly)
    points = []
    for i in range(limit):
        x = random.uniform(xlow, xhigh)
        y = random.uniform(ylow, yhigh)
        if CompGeom.point_in_poly(x, y, poly):
            points.append((x, y))
        if len(points) == npoints:
            break
    return points
Пример #5
0
def sample_with_rejection(npoints, poly, limit):
    """
    @param npoints: sample this many points with rejection
    @param poly: reject points outside the polygon
    @param limit: a sanity limit for rejection sampling
    @return: the sampled points
    """
    xpoly, ypoly = zip(*poly)
    xlow, xhigh = min(xpoly), max(xpoly)
    ylow, yhigh = min(ypoly), max(ypoly)
    points = []
    for i in range(limit):
        x = random.uniform(xlow, xhigh)
        y = random.uniform(ylow, yhigh)
        if CompGeom.point_in_poly(x, y, poly):
            points.append((x, y))
        if len(points) == npoints:
            break
    return points
Пример #6
0
def get_intersecting_edges(points, edges):
    """
    Edges that share an endpoint do not count as conflicting.
    @param points: a list of numpy arrays each of length 2
    @param edges: a list of point index pairs
    @return: the set of edges that intersect at least one other edge
    """
    conflicts = set()
    sedgewick_points = [CompGeom.Point(p.tolist()) for p in points]
    for ea, eb in itertools.combinations(edges, 2):
        # only check intersection when each endpoint is unique
        if len(set([ea[0], ea[1], eb[0], eb[1]])) == 4:
            a = sedgewick_points[ea[0]]
            b = sedgewick_points[ea[1]]
            c = sedgewick_points[eb[0]]
            d = sedgewick_points[eb[1]]
            if CompGeom.line_segments_intersect(a, b, c, d):
                conflicts.add(ea)
                conflicts.add(eb)
    return conflicts