本文整理汇总了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())
示例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)