当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.set_points方法代码示例

本文整理汇总了Python中Polygon.Polygon.set_points方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.set_points方法的具体用法?Python Polygon.set_points怎么用?Python Polygon.set_points使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon.Polygon的用法示例。


在下文中一共展示了Polygon.set_points方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RandPolygon

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import set_points [as 别名]
class RandPolygon(object):
    def __init__(self,minDist=100,maxDist=1000,minPoints=3,maxPoints=1000,startY=33.230073,startX=-97.143826):
        self.minDist = minDist
        self.maxDist = maxDist
        self.minPoints = minPoints
        self.maxPoints = maxPoints
        self.randPoints = random.randrange(self.minPoints,self.maxPoints)
        self.startX = startX
        self.startY = startY

        self.currIteration = 0.0
        self.maxIteration = self.maxPoints

        self.polygon = Polygon()
        self.points = []

        self.generatePolygon()

    def destination(self,x,y,angle, distance):
        """
        Displace a LatLng angle degrees counterclockwise and some
        meters in that direction.
        Notes:
            http://www.movable-type.co.uk/scripts/latlong.html
            0 DEGREES IS THE VERTICAL Y AXIS! IMPORTANT!
        Args:
            angle:    A number in degrees.
            distance: A number in meters.
        Returns:
            A new LatLng.
        """
        angle = np.float32(angle)

        delta = np.divide(np.float32(distance), np.float32(3959))

        angle = self.deg2rad(angle)
        y1 = self.deg2rad(y)
        x1 = self.deg2rad(x)

        y2 = np.arcsin( np.sin(y1) * np.cos(delta) +
                          np.cos(y1) * np.sin(delta) * np.cos(angle) )

        x2 = x1 + np.arctan2( np.sin(angle) * np.sin(delta) * np.cos(y1),
                                  np.cos(delta) - np.sin(y1) * np.sin(y2))

        x2 = (x2 + 3 * np.pi) % (2 * np.pi) - np.pi

        return [self.rad2deg(x2),self.rad2deg(y2)]

    def deg2rad(self,angle):
            return np.divide(np.dot(angle, np.pi), np.float32(180.0))

    def rad2deg(self,angle):
            return np.divide(np.dot(angle, np.float32(180.0)), np.pi)

    def generatePolygon(self):
        pts = []
        n = self.randPoints
        for i in range(n):
            angle = self.randAngle(i,n,"Degrees")
            distance = random.randrange(self.minDist,self.maxDist)
            #print angle,distance
            xy = self.destination(self.startX,self.startY,self.rad2deg(angle),distance)
            pts.append((xy[0],xy[1]))
            #print xy[1],",",xy[0],":",self.getPointAngle(xy[0],xy[1])
        self.polygon.set_points(pts,(self.startX,self.startY))
        self.polygon.orderPoints()
        pts = self.polygon.get_points()
        for p in pts:
            print p[1],",",p[0],":"


    def randDistance(self):
        random.randrange(self.minDist,self.maxDist)

    """
    @private
    @method - randAngle: Generates a random angle between the ith and ith + 1 iteration.
                         Meaning that if this function was called 4 times, it would successively
                         return angles: 0-90,90-180,180-270,270-360
    @param {int} i      : Current iteration count (or starting angle)
    @param {int} n      : Max iterations (or ending angle)
    @param {string}     : Radians or Degrees
    @returns list[]: list of items in node
    """
    def randAngle(self,i,n,Units="Radians"):
        i = float(i)
        n = float(n)
        value = (2.0 * math.pi) * random.uniform((i)/n , (i+1)/n)
        if Units == "Radians":
            return value
        else:
            return math.degrees(value)
开发者ID:rugbyprof,项目名称:4553-Spatial-DS,代码行数:95,代码来源:randomPolygon.py


注:本文中的Polygon.Polygon.set_points方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。