當前位置: 首頁>>代碼示例>>Python>>正文


Python spatial.ConvexHull方法代碼示例

本文整理匯總了Python中scipy.spatial.ConvexHull方法的典型用法代碼示例。如果您正苦於以下問題:Python spatial.ConvexHull方法的具體用法?Python spatial.ConvexHull怎麽用?Python spatial.ConvexHull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.spatial的用法示例。


在下文中一共展示了spatial.ConvexHull方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_chempot_qhull

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def get_chempot_qhull(self):
        faces = list(self.hull)
        A = []
        for face in faces:
            A.append([face.chem_pots[e] for e in self.elements])
        A = np.array(A)

        conv_hull = ConvexHull(A)

        uhull = set()
        for facet in conv_hull.simplices:
            face = frozenset([ faces[i] for i in facet 
                if i < len(faces) ])
            uhull.add(face)

        return uhull 
開發者ID:wolverton-research-group,項目名稱:qmpy,代碼行數:18,代碼來源:space.py

示例2: compute_convex_hull

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def compute_convex_hull(landmarks):
    """ compute convex hull around landmarks

    * http://lagrange.univ-lyon1.fr/docs/scipy/0.17.1/generated/scipy.spatial.ConvexHull.html
    * https://stackoverflow.com/questions/21727199

    :param ndarray landmarks: set of points
    :return ndarray: pints of polygon

    >>> np.random.seed(0)
    >>> pts = np.random.randint(15, 30, (10, 2))
    >>> compute_convex_hull(pts)
    array([[27, 20],
           [27, 25],
           [22, 24],
           [16, 21],
           [15, 18],
           [26, 18]])
    """
    chull = spatial.ConvexHull(landmarks)
    chull_points = landmarks[chull.vertices]
    return chull_points 
開發者ID:Borda,項目名稱:BIRL,代碼行數:24,代碼來源:dataset.py

示例3: get_polygon_center

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def get_polygon_center(pc):
    # hull = ConvexHull(pc)
    # import pdb; pdb.set_trace()
    # try:
    #    pc_new = pc[hull.vertices,:]
    # except:
    #    import pdb; pdb.set_trace()
    # return np.sum(pc_new, axis = 0)/ len(pc_new)
    # try:

    sample_size = 100
    if len(pc) > sample_size:
        random.sample(np.arange(len(pc)).tolist(), sample_size)

    pc = np.array(pc)
    center = np.sum(pc, axis=0) / len(pc)
    circle = smallestenclosingcircle.make_circle(pc[:, 0:2])
    #    except:
    #        import pdb; pdb.set_trace()
    return np.array([circle[0], circle[1], center[2]]) 
開發者ID:alliecc,項目名稱:argoverse_baselinetracker,代碼行數:22,代碼來源:tools_pcl.py

示例4: buffer_shape

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def buffer_shape(shape, radius, sides=4):
    '''
    Return a buffered version of a shape.
    The buffer radius is radius.
    '''
    if isinstance(shape, b2CircleShape):
        return b2CircleShape(pos=shape.pos, radius=shape.radius+radius)
    thetas = [(i+.5)*2*np.pi/sides for i in xrange(sides)]
    buffer_vertices = [radius*np.array([np.cos(theta), np.sin(theta)]) for theta in thetas]
    new_vertices = []
    for v in shape.vertices:
        for b in buffer_vertices:
            new_vertices.append(np.array(v) + b)
    hull = ConvexHull(new_vertices)
    hull_vertices = [tuple(new_vertices[i]) for i in hull.vertices]
    return b2PolygonShape(vertices=hull_vertices) 
開發者ID:zi-w,項目名稱:Kitchen2D,代碼行數:18,代碼來源:gripper.py

示例5: get_mar

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def get_mar(polygon):
    """ Given a list of points, returns a minimum area rectangle that will
    contain all points. It will not necessarily be vertically or horizontally
     aligned.
    Returns
    -------
    list((int, int)): 4 corner points of rectangle.
    """
    polygon = tuple(polygon)
    hull_ordered = [polygon[index] for index in ConvexHull(polygon).vertices]
    hull_ordered.append(hull_ordered[0])
    hull_ordered = tuple(hull_ordered)
    min_rectangle = _bounding_area(0, hull_ordered)
    for i in range(1, len(hull_ordered) - 1):
        rectangle = _bounding_area(i, hull_ordered)
        if rectangle['area'] < min_rectangle['area']:
            min_rectangle = rectangle

    min_rectangle['unit_vector_angle'] = atan2(min_rectangle['unit_vector'][1], min_rectangle['unit_vector'][0])
    min_rectangle['rectangle_center'] = _to_xy_coordinates(min_rectangle['unit_vector_angle'],
                                                           min_rectangle['rectangle_center'])
    points_list = _rectangle_corners(min_rectangle)
    return points_list 
開發者ID:waldo-seg,項目名稱:waldo,代碼行數:25,代碼來源:mar_utils.py

示例6: get_linear_inequalities

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def get_linear_inequalities(self):
        """
        Returns the linear inequalities defining the zontope vertices, i.e., Ax<=b.

        :param Subspaces self:
            An instance of the Subspaces object.

        :return:
            **A**: The matrix for setting the linear inequalities.
        :return:
            **b**: The right-hand-side vector for setting the linear inequalities.
        """
        if self.Y is None:
            self.Y = self.get_zonotope_vertices()
        n = self.Y.shape[1]
        if n == 1:
            A = np.array([[1],[-1]])
            b = np.array([[max(self.Y)],[min(self.Y)]])
            return  A, b
        else:
            convexHull = ConvexHull(self.Y)
            A = convexHull.equations[:,:n]
            b = -convexHull.equations[:,n]
            return A, b 
開發者ID:Effective-Quadratures,項目名稱:Effective-Quadratures,代碼行數:26,代碼來源:subspaces.py

示例7: draw_cube

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def draw_cube():
    """
    Draws a cube using only the vertices.
    Obtains faces using the scipy convex hull
    method.
    """
    c = Cube(3)
    verts = np.array([i.binary for i in c.vertices])-np.array([.5,.5,.5])
    hull = ConvexHull(verts)
    simps = hull.simplices
    planes = np.array([[verts[j] for j in i] for i in simps])
    for i in range(20):
        im = Image.new("RGB", (2048, 2048), (1,1,1))
        draw = ImageDraw.Draw(im,'RGBA')
        r = np.transpose(rotation(3,np.pi*(9+i)/15)) #i=9
        planes = [orient_face(pl) for pl in planes]
        render_solid_planes(planes, draw, r)
        im.save(".\\im" + str(i) + ".png") 
開發者ID:ryu577,項目名稱:pyray,代碼行數:20,代碼來源:polyhedron.py

示例8: drawSamples

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def drawSamples(self, nsamples):
        import matplotlib.pyplot as plt
        plt.figure(1)
        plt.clf()
        plt.hold(True)
        k = ConvexHull(self.bot_pts.T).vertices
        k = np.hstack((k, k[0]))
        n = self.planar_polyhedron.generators.shape[0]
        plt.plot(self.planar_polyhedron.generators.T[0,list(range(n)) + [0]],
                 self.planar_polyhedron.generators.T[1,list(range(n)) + [0]], 'r.-')
        samples = sample_convex_polytope(self.c_space_polyhedron.A,
                                         self.c_space_polyhedron.b,
                                         500)
        for i in range(samples.shape[1]):
            R = np.array([[np.cos(samples[2,i]), -np.sin(samples[2,i])],
                          [np.sin(samples[2,i]), np.cos(samples[2,i])]])
            V = R.dot(self.bot_pts[:,k])
            V = V + samples[:2, i].reshape((2,1))
            plt.plot(V[0,:], V[1,:], 'k-')
        plt.show() 
開發者ID:RobotLocomotion,項目名稱:director,代碼行數:22,代碼來源:terrain.py

示例9: find_perimeter_nodes

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def find_perimeter_nodes(graph):
    """Find nodes on the perimeter of a graph.

    Uses a convex hull to locate the perimeter nodes of a graph.

    Parameters
    ----------
    graph : graph_like
        A Graph of nodes (just requires *xy_of_node*).

    Returns
    -------
    ndarray of int
        Identifiers of the perimeter nodes.
    """
    from scipy.spatial import ConvexHull

    hull = ConvexHull(graph.xy_of_node, qhull_options="Qt")
    return as_id_array(hull.vertices) 
開發者ID:landlab,項目名稱:landlab,代碼行數:21,代碼來源:graph.py

示例10: cvHull

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def cvHull(pL):
    if len(pL) < 3:
        return pL
    from scipy.spatial import ConvexHull
    from scipy.spatial.qhull import QhullError
    S = [xx.std() for xx in pL]
    try:
        hull = ConvexHull(S)
    except QhullError:
        xL = [xx.x for xx in pL]
        xx, pL = order(xL, pL)
        return [pL[0], pL[-1]]
    P = [pL[i] for i in hull.vertices]
    P.append(pL[hull.vertices[0]])
    return P 
開發者ID:kamalshadi,項目名稱:Localization,代碼行數:17,代碼來源:geometry.py

示例11: convex_hull_intersection

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def convex_hull_intersection(p1, p2):
    """ Compute area of two convex hull's intersection area.
        p1,p2 are a list of (x,y) tuples of hull vertices.
        return a list of (x,y) for the intersection and its volume
    """
    inter_p = polygon_clip(p1,p2)
    if inter_p is not None:
        hull_inter = ConvexHull(inter_p)
        return inter_p, hull_inter.volume
    else:
        return None, 0.0 
開發者ID:zaiweizhang,項目名稱:H3DNet,代碼行數:13,代碼來源:box_util.py

示例12: _convex_completion

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def _convex_completion(self, arr):
        blob_points = np.transpose(np.nonzero(arr))
        assert len(blob_points) >= 3

        hull = ConvexHull(blob_points)

        for simplex in hull.simplices:
            line_start, line_end = blob_points[simplex[0]], blob_points[simplex[1]]
            arr = self._draw_line(arr, line_start, line_end)

        arr = crop(arr)
        arr = self._fill_interior(arr)

        return arr 
開發者ID:vicariousinc,項目名稱:pixelworld,代碼行數:16,代碼來源:pattern_generator.py

示例13: get_polygon_area

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def get_polygon_area(pc):

    #    import pdb; pdb.set_trace()
    try:
        pc = np.array(pc)
        hull = ConvexHull(pc[:, 0:2])
        return Polygon(pc[hull.vertices, 0:2]).area
    except:
        return 0 
開發者ID:alliecc,項目名稱:argoverse_baselinetracker,代碼行數:11,代碼來源:tools_pcl.py

示例14: drizzle_footprint

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def drizzle_footprint(weight_image, shrink=10, ext=0, outfile=None, label=None):
    """
    Footprint of image pixels where values > 0.  Works best with drizzled
    weight images.
    """
    from scipy.spatial import ConvexHull

    im = pyfits.open(weight_image)
    wcs = pywcs.WCS(im[ext].header, fobj=im)
    sh = np.array(im[ext].data.shape)//shrink

    yp, xp = np.indices(tuple(sh))*shrink
    nonzero = im[ext].data[yp, xp] > 0

    h = ConvexHull(np.array([xp[nonzero], yp[nonzero]]).T)
    hx = xp[nonzero][h.vertices]
    hy = yp[nonzero][h.vertices]

    hrd = wcs.all_pix2world(np.stack([hx, hy]).T, 0)

    pstr = 'polygon('+','.join(['{0:.6f}'.format(i) for i in hrd.flatten()])+')'
    if label is not None:
        pstr += ' # text={{{0}}}'.format(label)

    if outfile is None:
        return pstr

    fp = open(outfile, 'w')
    fp.write('fk5\n')

    fp.write(pstr+'\n')
    fp.close() 
開發者ID:gbrammer,項目名稱:grizli,代碼行數:34,代碼來源:prep.py

示例15: convex_hull_intersection

# 需要導入模塊: from scipy import spatial [as 別名]
# 或者: from scipy.spatial import ConvexHull [as 別名]
def convex_hull_intersection(p1, pt):
    """
    compute area of two convex hull's intersection area
    :param p1: a list of (x,y) tuples of hull vertices
    :param pt: a list of (x,y) tuples of hull vertices
    :return:
        a list of (x,y) for the intersection and its volume
    """
    inter_p = polygon_clip(p1, pt)
    if inter_p is not None:
        hull_inter = ConvexHull(inter_p)
        return inter_p, hull_inter.volume
    else:
        return None, 0.0 
開發者ID:mit-han-lab,項目名稱:pvcnn,代碼行數:16,代碼來源:utils.py


注:本文中的scipy.spatial.ConvexHull方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。