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


Python Polygon.center方法代碼示例

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


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

示例1: rackGear

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import center [as 別名]
def rackGear(pos=(0,0), n=30, radius=5., phi=20., addendum=0.4, dedendum=0.5,
         fradius=0.1, rotate=0, scale=1.0, length=10*pi, res=1, bevel=0.05, depth=(0.4+0.6+0.1)):
        tooth = RackOutline(n, res, phi, radius, addendum, dedendum,
                        fradius, bevel)

        toothl = tooth[0][1] - tooth[-1][1]

        ntooth = int(length/toothl)
        flength = ntooth * toothl

        gear = []
        for i in range(0, ntooth):
            ntooth = []
            for (x, y) in tooth:
                nx = x + pos[0]
                ny = -i*toothl + y + pos[1]
                ntooth.append((nx,ny))
            gear.extend(ntooth)
        gear.append((gear[-1][0]-depth,gear[-1][1]))
        gear.append((gear[0][0]-depth,gear[0][1]))
        gear.append(gear[0])
        pp =  Polygon(gear)
        pp.shift(-pp.center()[0],-pp.center()[1])
        if rotate != 0.0: pp.rotate(rotate)
        if scale != 1.0 : pp.scale(scale,scale)
        return pp
開發者ID:Emma920,項目名稱:visual,代碼行數:28,代碼來源:shapes.py

示例2: shape_center

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import center [as 別名]
def shape_center(shape):
	"""
	computes the center of gravity of a shapefile multi-polygon
	"""
	from Polygon import Polygon
	parts = shape.parts[:]
	parts.append(len(shape.points))
	
	# check for countries that cross the 180° longitude
	
	far_east = False
	far_west = False
	
	for i in range(len(parts)-1):
		pts = shape.points[parts[i]:parts[i+1]]
		if len(pts) == 0: continue
		if pts[0][0] < -90:
			far_west = True
		if pts[0][0] > 90:
			far_east = True
	
	poly = Polygon()
	for i in range(len(parts)-1):
		pts = shape.points[parts[i]:parts[i+1]]
		if far_east and far_west:
			# correct points
			for j in range(len(pts)):
				if pts[j][0] < 0: pts[j][0] += 360
		poly.addContour(pts)
	return poly.center()
開發者ID:kartograph,項目名稱:kartograph.py-old,代碼行數:32,代碼來源:gisutils.py

示例3: center

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import center [as 別名]
 def center(self):
     ret = [0, 0]
     if self.type() == 'MultiPolygon':
         p = Polygon(self.coordinates()[0][0])
         ret = list(p.center())
     else:
         ret = self.coordinates()
         
     c = transform_to_4326(self.crs_code(), ret[0], ret[1])
     
     return [c[0], c[1]]
開發者ID:KDMgit,項目名稱:geonode,代碼行數:13,代碼來源:models.py

示例4: polygon_center

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import center [as 別名]
def polygon_center(polygon):
	"""
	computes the center of gravity of a gisutils.Polygon
	"""
	from Polygon import Polygon as Poly
	pts = []
	for pt in polygon.points:
		pts.append((pt.x, pt.y))
	poly = Poly(pts)
	c = poly.center()
	return Point(c[0], c[1])
開發者ID:kartograph,項目名稱:kartograph.py-old,代碼行數:13,代碼來源:gisutils.py

示例5: __init__

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import center [as 別名]
class Shape:
    """Graphical polygon primitive for use with `pyglet`_.

    Alternative constructor methods:

    - |Shape.circle|
    - |Shape.rectangle|
    - |Shape.regular_polygon|
    - |Shape.from_dict|

    Parameters
    ----------
    vertices : array-like or |Polygon|.
        If a |Polygon| is passed, its points will be used.
        Otherwise, `vertices` should be a sequence of `[x, y]` locations or an array with x and y columns.
    color : str or 3-tuple of int, optional
        Color, in R, G, B format.
        Alternatively, a key that refers to an element of `colors`.
    velocity : array-like
        Speed and direction of motion, in [dx_dt, dy_dt] format.
    angular_velocity : float
        Speed of angular motion, in counter-clockwise radians per second.
    colors : dict of tuple, optional
        Named colors, defined as R, G, B tuples.
        Useful for easily switching between a set of colors.

    Attributes
    ----------
    poly : |Polygon|
        Associated |Polygon| object.
    vertices : |array|
        An array of points, with x and y columns. Read-only.
    center : |array|
        The centroid of the shape.
        Setting center calls |Shape.translate|.
    position : |array|
        Alias for `center`.
    radius : |array|
        Mean distance from each point to the center.
        Setting radius calls |Shape.scale|.
    color : str or tuple of int
        The current color, in R, G, B format if `colors` was not passed.
        Otherwise, the current color is represented as a key in `colors`.
    colors : dict of tuple
        Named colors.
    velocity : |array|
        Speed and direction of linear motion.
    Angular_velocity : float
        Speed of angular motion, in counter-clockwise radians per second.
    enabled : bool
        If False, the shape will not be drawn.

    """

    def __init__(self, vertices, color=(255, 255, 255), velocity=(0, 0), angular_velocity=0, colors=None):
        if isinstance(vertices, Polygon):
            self.poly = vertices
        else:
            self.poly = Polygon(vertices)

        self.colors = colors
        self._color = "primary"
        if colors:
            self.color = color

        else:
            self.colors = {"primary": color}

        self.velocity = np.asarray(velocity)
        self.angular_velocity = angular_velocity

        # Construct vertex_list.
        self._vertex_list = self._get_vertex_list()
        self.enabled = True

    @classmethod
    def regular_polygon(cls, center, radius, n_vertices, start_angle=0, **kwargs):
        """Construct a regular polygon.

        Parameters
        ----------
        center : array-like
        radius : float
        n_vertices : int
        start_angle : float, optional
            Where to put the first point, relative to `center`,
            in radians counter-clockwise starting from the horizontal axis.
        kwargs
            Other keyword arguments are passed to the |Shape| constructor.

        """
        angles = (np.arange(n_vertices) * 2 * np.pi / n_vertices) + start_angle
        return cls(center + radius * np.array([np.cos(angles), np.sin(angles)]).T, **kwargs)

    @classmethod
    def circle(cls, center, radius, n_vertices=50, **kwargs):
        """Construct a circle.

        Parameters
        ----------
#.........這裏部分代碼省略.........
開發者ID:hsharrison,項目名稱:pyglet2d,代碼行數:103,代碼來源:pyglet2d.py


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