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


Python Point.length方法代码示例

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


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

示例1: calcMotionEnergy

# 需要导入模块: from Point import Point [as 别名]
# 或者: from Point.Point import length [as 别名]
	def calcMotionEnergy(self):
		n = len(self.points)
		l = 3
		speed = []
		for i in range(0,n-l-1):
			a,b = self.points[i].getCoords()
			dx = dy = 0
			for j in range(l):
				index = i+j+1
				c,d = self.points[i+l+1].getCoords()

				dx = dx + c - a
				dy = dy + d - b

			dx = dx/l
			dy = dy/l

			d = Point(dx, dy)
			speed.append(d)

		n = len(speed)

		if n == 0:
			return 0
			
		e = Point(0, 0)
		mx = my = 0
		for i in range(0,n):
			a,b = speed[i].getCoords()
			mx = mx + a
			my = my + b

		mx = mx/n
		my = my/n

		for i in range(0,n):
			a,b = speed[i].getCoords()

			dx = mx - a
			dy = my - b

			dx2 = dx*dx
			dy2 = dy*dy

			e.x = e.x + dx2
			e.y = e.y + dy2

		print(str(n-1))
		e.x = e.x/(n-1)
		e.y = e.y/(n-1)

		return e.length()
开发者ID:datjwu,项目名称:CMC_Integration,代码行数:54,代码来源:TrackInfo.py

示例2: setFromQTransform

# 需要导入模块: from Point import Point [as 别名]
# 或者: from Point.Point import length [as 别名]
 def setFromQTransform(self, tr):
     p1 = Point(tr.map(0., 0.))
     p2 = Point(tr.map(1., 0.))
     p3 = Point(tr.map(0., 1.))
     
     dp2 = Point(p2-p1)
     dp3 = Point(p3-p1)
     
     ## detect flipped axes
     if dp2.angle(dp3) > 0:
         #da = 180
         da = 0
         sy = -1.0
     else:
         da = 0
         sy = 1.0
         
     self._state = {
         'pos': Point(p1),
         'scale': Point(dp2.length(), dp3.length() * sy),
         'angle': (np.arctan2(dp2[1], dp2[0]) * 180. / np.pi) + da
     }
     self.update()
开发者ID:archphy,项目名称:poropy,代码行数:25,代码来源:Transform.py

示例3: calcDirection

# 需要导入模块: from Point import Point [as 别名]
# 或者: from Point.Point import length [as 别名]
	def calcDirection(self):
		del self.direction[:]
		n = len(self.points)
		for i in range(0,n-1):
			a,b = self.points[i].getCoords()
			c,d = self.points[i+1].getCoords()

			dx = c - a
			dy = d - b

			d = Point(dx, dy)

			if d.length() < 0.001:
				d = Point(0, 0)
			else:
				d.normalize()

			self.direction.append(d)
开发者ID:datjwu,项目名称:CMC_Integration,代码行数:20,代码来源:TrackInfo.py

示例4: Brick

# 需要导入模块: from Point import Point [as 别名]
# 或者: from Point.Point import length [as 别名]
class Brick(Enemy):
    def __init__(self, scene, x, y, n=2):
        super().__init__(scene, x, y)
        self._velocity = Point(0, 0)
        self._size = n
        myscale = SCALE - n*2
        self.set_shape(sh.BRICK_SHAPE[n], Colors.split, True, myscale)
        self._sleep = SLEEP_TIME if n < 2 else 0

    def destroy(self):
        if self._size > 0:
            s = SCALE
            off = self._size*s
            n = self._size - 1
            for x in range(0, 2):
                for y in range(0, 2):
                    celloffset = Point(off + x*s, off + y*s)
                    cellpos = self.position + celloffset
                    child = Brick(self._scene, cellpos.x, cellpos.y, n)
                    child._velocity = (cellpos - self.position)*2
                    self._scene.add_object(child)

        super().destroy()

    def update(self):
        if self._sleep <= 0:
            player = self._scene.player
            dirvec = player.position - self.position
            self._velocity += dirvec * ACCELERATION / dirvec.length()
        else:
            self._sleep -= 1

        if self._velocity.length_sqr() > SPEED:
                self._velocity.normalize()
                self._velocity *= SPEED

        self.position += self._velocity
        self.direction += self._velocity.length()*ANGULAR_SPEED
        super().update()
开发者ID:Botyto,项目名称:PythonGeometryWars,代码行数:41,代码来源:Brick.py


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