Example #1
0
def farthest(pts, xlims, ylims, n):
    """ Find the 'n' points that lie farthest from the points given
    in the region bounded by 'xlims' and 'ylims'.
    'pts' is an array of points.
    'xlims' and 'ylims are tuples storing the maximum and minimum
    values to consider along the x and y axes."""
    # There are a ton of ways to do this, this is a shorter one.
    # The 'inside' function tests whether or not a point is on
    # the interior of the given square.
    ins = lambda pt: inside(pt, xlims, ylims)
    # Construct the Voronoi diagram.
    V = st.Voronoi(pts)
    # Construct the KD Tree.
    KD = st.cKDTree(pts)
    # Now we'll construct a list of tuples where the first
    # entry is the distance from a point to the nearest node
    # and the second entry is a tuple with the coordinates for the point.
    # Process the vertices of the Voronoi diagram.
    Q = [(KD.query(pt)[0], pt) for pt in V.vertices if ins(pt)]
    # Process the intersections of the edges of the
    # Voronoi diagram and the edges of the box.
    Q += [(KD.query(pt)[0], pt) for pt in edge_intersections(V, xlims, ylims)[0]]
    # Process the corners of the box.
    Q += [(KD.query(pt)[0], (x, y)) for x in xlims for y in ylims]
    # Return the 'n' points with farthest distance from the points
    # used to generate the Voronoi diagram.
    return np.array([pair[1] for pair in hq.nlargest(n, Q)])
Example #2
0
def farthest(pts, xlims, ylims, n):
    """ Find the 'n' points that lie farthest from the points given
    in the region bounded by 'xlims' and 'ylims'.
    'pts' is an array of points.
    'xlims' and 'ylims are tuples storing the maximum and minimum
    values to consider along the x and y axes."""
    # There are a ton of ways to do this, this is a shorter one.
    # The 'inside' function tests whether or not a point is on
    # the interior of the given square.
    ins = lambda pt: inside(pt, xlims, ylims)
    # Construct the Voronoi diagram.
    V = st.Voronoi(pts)
    # Construct the KD Tree.
    KD = st.cKDTree(pts)
    # Now we'll construct a list of tuples where the first
    # entry is the distance from a point to the nearest node
    # and the second entry is a tuple with the coordinates for the point.
    # Process the vertices of the Voronoi diagram.
    Q = [(KD.query(pt)[0], pt) for pt in V.vertices if ins(pt)]
    # Process the intersections of the edges of the
    # Voronoi diagram and the edges of the box.
    Q += [(KD.query(pt)[0], pt) for pt in edge_intersections(V, xlims, ylims)[0]]
    # Process the corners of the box.
    Q += [(KD.query(pt)[0], (x, y)) for x in xlims for y in ylims]
    # Return the 'n' points with farthest distance from the points
    # used to generate the Voronoi diagram.
    return np.array([pair[1] for pair in hq.nlargest(n, Q)])
def farthest(pts, xlims, ylims, n):
    # there are a ton of ways to do this, this is a shorter one
    ins = lambda pt: inside(pt, xlims, ylims)
    V = st.Voronoi(pts)
    KD = st.cKDTree(pts)
    Q = [(KD.query(pt)[0],pt) for pt in V.vertices if ins(pt)]
    Q += [(KD.query(pt)[0],pt) for pt in edge_intersections(V, xlims, ylims)[0]]
    return np.array([pair[1] for pair in hq.nlargest(n,Q)])
Example #4
0
def farthest(pts, xlims, ylims, n):
    # there are a ton of ways to do this, this is a shorter one
    ins = lambda pt: inside(pt, xlims, ylims)
    V = st.Voronoi(pts)
    KD = st.cKDTree(pts)
    Q = [(KD.query(pt)[0], pt) for pt in V.vertices if ins(pt)]
    Q += [(KD.query(pt)[0], pt)
          for pt in edge_intersections(V, xlims, ylims)[0]]
    return np.array([pair[1] for pair in hq.nlargest(n, Q)])
def make_adj(V, xlims, ylims, threshold):
    ins = lambda pt: inside(pt, xlims, ylims)
    size = V.vertices.shape[0]
    A = np.zeros((size,size),dtype=bool)
    for edge, centers in zip(V.ridge_vertices, V.ridge_points):
        if -1 not in edge:
            if threshold <= sqrt(np.sum((V.points[centers[0]]-V.points[centers[1]])**2))/2.:
                A[edge[0],edge[1]] = True
    A += A.T
    return A
Example #6
0
def make_adj(V, xlims, ylims, threshold):
    ins = lambda pt: inside(pt, xlims, ylims)
    size = V.vertices.shape[0]
    A = np.zeros((size, size), dtype=bool)
    for edge, centers in zip(V.ridge_vertices, V.ridge_points):
        if -1 not in edge:
            if threshold <= sqrt(
                    np.sum((V.points[centers[0]] - V.points[centers[1]])**
                           2)) / 2.:
                A[edge[0], edge[1]] = True
    A += A.T
    return A