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


Python Vector.normalized方法代码示例

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


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

示例1: main

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import normalized [as 别名]
def main():


    my_vector1 = Vector([8.218,-9.341])
    my_vector2 = Vector([-1.129,2.111])
    my_vector3 = Vector([7.119, 8.215])
    my_vector4 = Vector([-8.223, 0.878])
    my_vector5 = Vector([1.671,-1.012,-0.318])


    my_vector = [1,2,3]
    scalar = 7.41
    # c = tuple([item1+item2 for item1, item2 in zip( a, b)])

    print(my_vector1 + my_vector2)
    print(my_vector3 - my_vector4)
    print( my_vector5.times_scalar(scalar))
    
    print(my_vector1.magnitude)
    print(my_vector4.normalized())
开发者ID:dmadam,项目名称:LiniarAlgebra,代码行数:22,代码来源:vector_test.py

示例2: Boid

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import normalized [as 别名]
class Boid(Circle):
    def __init__(self):
        Circle.__init__(self, C.BOID_RADIUS, C.BOID_COLOR, None)
        self.pos = Vector(random.randint(0, C.SCREEN.get_width()), random.randint(0, C.SCREEN.get_height()))
        self.velocity = C.BOID_VELOCITY
        self.dir = Vector(random.randint(-10, 10),random.randint(-10, 10)).normalized() * self.velocity
    
    def draw_tail(self):
        v = self.dir.normalized() * -abs(1) * C.BOID_TAIL_LENGTH        
        pygame.draw.line(C.SCREEN, self.color, (self.pos.x, self.pos.y), (self.pos.x + v.x, self.pos.y+v.y))
        
    @classmethod
    def rule1(self, this_boid, boids, flock):
        for boid in boids:
            if boid is not this_boid and (boid.pos - this_boid.pos).magnitude() < 70:
                flock.append(boid)
        if len(flock) > 0:
            avg = Vector.average([boid.pos for boid in flock])
            return (avg - this_boid.pos)*(50.0/100.0)
        return Vector(0, 0)

    @classmethod
    def rule2(self, this_boid, flock):
        v = Vector(0, 0)
        for boid in flock:
            if boid is not self:
                d = boid.pos - this_boid.pos
                if d.magnitude() < 15:
                    v -= d 
        return v *3
    
    @classmethod
    def rule3(self, this_boid, flock):
        avg = Vector.average([boid.dir for boid in flock])
        return avg - this_boid.dir * (1.0/8.0)
    
    @classmethod
    def rule4(self, this_boid, obstacles):
        v = Vector(0,0)
        for obstacle in obstacles:
            c = obstacle.pos - this_boid.pos
            if (c.magnitude() < (obstacle.radius + this_boid.radius + 20)):
                v -= c
        return v * 4
    
    @classmethod
    def rule5(self, this_boid, hoiks):
        v = Vector(0,0)
        for hoik in hoiks:
            c = hoik.pos - this_boid.pos
            if (c.magnitude() < (hoik.radius + this_boid.radius + 10)):
                v -= c
            
        return v * 10
    
    @classmethod
    def rule6(self, this_boid, foods):
        v = Vector(0,0)
        for food in foods:
            c = food.pos - this_boid.pos
            if (c.magnitude() < (food.radius + this_boid.radius +200)):
                v = c
        return v * 10
    
    @classmethod
    def rule7(self, this_boid):
        v = Vector(0, 0)
        if this_boid.pos.x < 10:
            v.x = 20
        elif this_boid.pos.x > C.SCREEN_SIZE.x-10:
            v.x = -20
        if this_boid.pos.y < 10:
            v.y = 20
        elif this_boid.pos.y > C.SCREEN_SIZE.y-10:
            v.y = -20
        return v
    
    def eat(self, foods):
        for food in foods:
            if self.intersect_circle(food.pos, food.radius):
                foods.remove(food)
开发者ID:EinarKristoffersen,项目名称:Python,代码行数:83,代码来源:Boid.py


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