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


Python Vector.length方法代码示例

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


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

示例1: Car

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import length [as 别名]
class Car(object):
    def __init__(self, position):
        self.position = position
        self.velocity = Vector(0, 0)
        self.alive = True

    def update(self, dt, height, acceleration, tangent):
        drag = -self.velocity.normalized() if self.velocity.length() > 0 else \
            Vector(0, 0)
        if height > 0:
            acc = tangent * acceleration + tangent * GRAVITY.dot(tangent) \
                - drag
        else:
            acc = GRAVITY - drag
        velocity_old = self.velocity
        self.velocity = self.velocity + acc * dt

        # Check death.
        impulse = (velocity_old - self.velocity).length()
        print "impulse:", impulse
        if impulse > 150:
            print "DIE!"
            self.alive = False

        self.position = self.position + self.velocity * dt
开发者ID:baskus,项目名称:graphbots,代码行数:27,代码来源:car.py

示例2: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import length [as 别名]
class MovingBall :

    r = 25

    #velocity vector

    speedlimit = Vector(10000.0, 10000.0) 

    color = pygame.color.Color('darkgreen')

    def __init__ (self, x, y, r, color, xv, yv):
        self.position = Vector(float(x), float(y))
        self.r = r
        self.color = color
        self.v = Vector(float(xv),float(yv))

    def stop_v (self):
        """ Reset the velocity to 0 if it gets very close. """

        if self.v.length() < 3:
            self.v = Vector (0,0)
        
    def draw (self, window):
        pygame.draw.circle(window, self.color, (int(self.position.x),int(self.position.y)), self.r)
开发者ID:sn0ri,项目名称:evofab,代码行数:26,代码来源:moving_ball_2d.py

示例3: getValue

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import length [as 别名]
    def getValue(self, x, y):
        # project point (x, y) onto vector
        v1 = Vector(x - self.centerX, y - self.centerY)
        # vector
        p = v1.project(self.direction);
        # adjust so the point is correct
        p.x += self.centerX
        p.y += self.centerY
        # get the vector from the point to (x, y)
        d = Vector(x - p.x, y - p.y)
        l = d.length()
							
        # normal of current vector
        n = Vector(self.direction.y, -self.direction.x)
						
        # adjust for sign on each side of the vector
        p = v1.dot(n)
        sign = 1.0
        if p > 0:
            sign = -1.0
						
        #print self.waveLength
        #print math.sin(self.theta + sign * l / self.waveLength)
        return math.sin(self.theta + sign * l / self.waveLength);
开发者ID:madisonb,项目名称:PysiCrystals,代码行数:26,代码来源:cartesian_wave.py


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