本文整理汇总了Python中Vector.Vector.coord方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.coord方法的具体用法?Python Vector.coord怎么用?Python Vector.coord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.coord方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cavallo
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import coord [as 别名]
class Cavallo():
def __init__(self, pos = [130,0],vmax = 60., thePath=[]):
self.currentNode = 0
self.pathDir = 1
self.nodes = thePath.getNodes()
self.t = self.nodes[self.currentNode]
self.max_v = vmax
self.p = Vector(pos)
self.v = Vector([0., 0.])
self.max_see_ahead = 30
self.max_avoid_force = 1.5
self.obstacles = []
def setObstacles(self, obs):
self.obstacles = obs
def updatePosition(self, dt):
self.p = self.p + (self.v*dt)
def collisionDetector(self):
dynamic_length = self.v.mod()/self.max_v*self.max_see_ahead
ahead = self.p + self.v.norm(dynamic_length)
ahead2 = self.p + self.v.norm(dynamic_length*0.5)
obstacle = self.takeOver(ahead, ahead2)
avoidance = Vector()
if (obstacle.p.coord() != [-1, -1]):
avoidance = ahead-obstacle.p
if (avoidance.x() == 0):
avoidance = Vector([self.max_avoid_force, 0])
elif (avoidance.y() == 0):
avoidance = Vector([0, self.max_avoid_force])
return avoidance
def takeOver(self, ahead, ahead2):
obstacle = Obstacle([-1, -1])
min_distance = 9999.
for o in self.obstacles:
collision = self.lineIntersectsCircle(o, ahead, ahead2)
if (o.p.coord() != self.p.coord()): # avoid self veto
distance = o.p - self.p
if (distance.dot(ahead) > 0.):
if (collision and distance.mod() < min_distance):
obstacle = o
min_distance = obstacle.p.distance(self.p)
return obstacle
def lineIntersectsCircle(self, o, ahead, ahead2):
dist1 = o.p.distance(self.p)
dist2 = o.p.distance(ahead2)
return (o.p.distance(ahead) <= o.radius*1.5) or (dist2 <= o.radius*1.5) or (dist1<=(o.radius+15.))
def steering(self):
current_v = self.v.mod()
desired_velocity = (self.t-self.p).norm(current_v)
steering = (desired_velocity-self.v)
avoid = self.collisionDetector()
if (steering.mod() < avoid.mod()*2.5):
steering = avoid
else:
steering = steering + avoid
if (steering.mod() > 2.):
steering = steering.norm(2.)
# r = v*v/a_t
#if (steering.transv(self.v) != 0):
#r = self.v.mod()*self.v.mod()/steering.transv(self.v)
#k = 0.5
#print math.sqrt(k*r)
self.v = self.v + steering
self.v = self.v.norm(current_v)
def move(self, dt):
# FIXME SCEGLI STRATEGIA
self.pathFollowing()
self.speedUp()
self.steering()
self.updatePosition(dt)
def speedUp(self):
#FIXME assegna uno scatto
current_v = self.v.mod()
if (current_v == 0.):
# deve cambiare con il tipo di mossa
self.direzione = -0.7854
self.v = Vector([math.cos(self.direzione), math.sin(self.direzione)])
else:
updated_v = current_v + 1.
if (updated_v >= self.max_v):
updated_v = self.max_v
self.v = self.v.norm(updated_v)
def pursuit(self):
pass
#public function pursuit(t :Boid) :Vector3D {
#.........这里部分代码省略.........