def person_at_station(self, person): def by_weighted_distance(left, right): return cmp(left[1], right[1]) pp = self.platform queue_depths = [] line_weighting = 10.0 forward_berth_weighting = 4.0 for berth in range(0, self.berths): queue_depths.append( ( berth, ( float(len(self.view_queues[berth]) + len(self.berth_queues[berth])) * line_weighting + ( person.position - vec3(pp[0].x, pp[0].y - PRT.berth_length / 2 - berth * PRT.berth_length) ).length() - float(self.berths - berth) / forward_berth_weighting ), ) ) queue_depths.sort(by_weighted_distance) berth = queue_depths[0][0] self.view_queues[berth].append(person) person.manager = self.person_at_berth person.manager_args = [berth] person.waypoints = [ vec3(pp[1].x - 0.5, pp[0].y - PRT.berth_length / 2 - berth * PRT.berth_length), vec3(pp[0].x + 0.5, pp[0].y - PRT.berth_length / 2 - berth * PRT.berth_length), ] person.behaviors = [Separation(), FollowWaypoints(), Queuing(), InterpenetrationConstraint()] return DONT_PASSIVATE
def generate(self): while True: start = uniform(1, 199) if not prts_only: p = Person(interval=interval) p.behaviors = [Seek(), Separation()] p.position = vec3(0.0, start) platform_position = start * 54 / 199 - 27 p.destination = vec3(28, 100 + platform_position) p.manager = self.rail_station.person_at_platform activate(p, p.move(), 0.0) p = Person(interval=interval) p.behaviors = [Seek(), Separation()] p.position = vec3(100.0, start) platform_position = start * 8 / 199 if start < 100: p.destination = self.destination1.copy() p.manager = self.station1.person_at_station p.manager_args = [] else: p.destination = self.destination2.copy() p.manager = self.station2.person_at_station p.manager_args = [] activate(p, p.move(), 0.0) yield hold, self, 7
def test_intersection(self, boid, wall, position, vector): # From http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/ point1, point2 = wall denominator = ((vector.y * (point2[0] - point1[0])) - (vector.x * (point2[1] - point1[1]))) if denominator == 0.0: # parallel or coincident return False, None, None u_a = (vector.x * (point1[1] - position.y) - (vector.y) * (point1[0] - position.x)) / denominator u_b = ((point2[0] - point1[0]) * (point1[1] - position.y) - (point2[1] - point1[1]) * (point1[0] - position.x)) / denominator intersect = 0.0 < u_a < 1.0 and 0.0 < u_b < 1.0 if intersect: intersection = vec3(point1[0] + u_a * (point2[0] - point1[0]), point1[1] + u_a * (point2[1] - point1[1])) boid.intersection = intersection distance_along_check = u_b wall_vector = vec3(point1) - vec3(point2) wall_vector_normal = vec3( -wall_vector.y, wall_vector.x).normalize() boid.intersection_normal = wall_vector_normal normal_point = intersection + wall_vector_normal local_normal_point = boid.world.to_local(boid, normal_point) if local_normal_point.x <= 0.0: direction = 'left' else: direction = 'right' return True, distance_along_check, direction else: return False, None, None
def person(self, railcar, yy, railcar_waypoints): columns = self.columns compactness = self.compactness for ii in range(0, columns): xx = self.rail_x + (ii - (float(columns) - 1.0) / 2.0) * (Person.average_radius * 2.0 * compactness) p = Person(interval=interval) p.behaviors = [Containment(), Separation(), FollowWaypoints(), InterpenetrationConstraint()] p.steering_mind = queue_steering_mind p.position = vec3(xx, yy) p.waypoints = railcar_waypoints[0:] if self.mode == 'straight': if p.waypoints[0].y - self.waypoint_high.y > 3: p.waypoints.append(self.waypoint_high) if self.waypoint_low.y - p.waypoints[0].y > 3: p.waypoints.append(self.waypoint_low) elif self.mode == 'doorway': if p.waypoints[0].y > self.platform_center_y: p.waypoints.append(self.waypoint_high) if p.waypoints[0].y <= self.platform_center_y: p.waypoints.append(self.waypoint_low) p.waypoints.append(vec3(p.waypoints[-1])) p.waypoints[-1].x -= 7.0 elif self.mode == 'stair': p.waypoints.append(self.waypoint_low) p.waypoints.append(vec3(self.waypoint_low)) p.waypoints[-1].x -= self.doorway_width * 0.75 p.waypoints.append(self.waypoint_prt_door) p.waypoints.append(vec3(self.waypoint_prt_door)) p.waypoints[-1].x -= 1.0 p.manager = self.prt_station.person_at_station railcar.departing.append(p)
def calculate(self, boid): the_world = boid.world others = the_world.boids(boid, 4) speed = boid.velocity.length() local_front = vec3(0, 1) for other in others: local_position = the_world.to_local(boid, other.position) angle = local_position.angle(local_front) if local_position[1] > 0 and angle < pi / 8: if other.velocity.length() < speed: return -boid.localy.scale(speed / boid.max_speed) return vec3()
def distance_from_line(self, position, line): line_length = (vec3(line[1]) - vec3(line[0])).length() u = ((position.x - line[0][0]) * (line[1][0] - line[0][0]) + (position.y - line[0][1]) * (line[1][1] - line[0][1])) \ / line_length ** 2 if 0.0 < u < 1.0: # point is tangent to line x = line[0][0] + u * (line[1][0] - line[0][0]) y = line[0][1] + u * (line[1][1] - line[0][1]) vector = position - vec3(x, y) distance = vector.length() return True, distance, vector return False, None, None
def calculate(self, boid): the_world = boid.world walls = the_world.obstacles(boid) acceleration = vec3() front_intersect = left_intersect = right_intersect = False front_distance = left_distance = right_distance = 3000 speed = boid.velocity.length() front_check = 0.5 + speed * 1.5 side_check = 0.5 + speed * 0.5 front_test = boid.localy.scale(front_check) left_test = (boid.localy - boid.localx).scale(side_check) right_test = (boid.localy + boid.localx).scale(side_check) position = boid.position boid.intersection = None checked = [] for wall in walls: if wall in checked: continue checked.append(wall) intersect, distance_along_check, direction = self.test_intersection(boid, wall, position, front_test) if intersect and distance_along_check < front_distance: front_intersect = True front_distance = distance_along_check front_direction = direction intersect, distance_along_check, direction = self.test_intersection(boid, wall, position, left_test) if not front_intersect and intersect and distance_along_check < left_distance: left_intersect = True left_distance = distance_along_check left_direction = direction intersect, distance_along_check, direction = self.test_intersection(boid, wall, position, right_test) if not front_intersect and intersect and distance_along_check < right_distance: right_intersect = True right_distance = distance_along_check right_direction = direction speed = boid.velocity.length() / boid.max_speed if front_intersect: if front_direction == 'left': acceleration = -boid.localx.scale(speed) else: acceleration = boid.localx.scale(speed) elif left_intersect: acceleration = boid.localx.scale(speed) elif right_intersect: acceleration = -boid.localx.scale(speed) else: acceleration = vec3() return acceleration
def generate(self, interval, waypoints): people = [] rate = 0.5 #while True: for k in range(10): start = uniform(0, 5) p = Person(interval=interval) #p.destination= vec3(12.5,uniform(2,20)) p.behaviors = [Containment(), Separation(), Queuing(), FollowWaypoints(), InterpenetrationConstraint()] #p.behaviors = [FollowWaypoints(),InterpenetrationConstraint()] #p.behaviors = [Seek(),InterpenetrationConstraint()] p.steering_mind = queue_steering_mind p.position = vec3(start, 0.0) p.waypoints = waypoints[0:] activate(p, p.move(), 0.0) people.append(p) count = 0 for p in people: if p.position[1] > 25: self.cancel(p) p.world.remove_boid(p) people.remove(p) if p.position[1] < 7: count += 1 if count > 30: rate = 1.5 elif count < 20: rate = 0.5 yield hold, self, rate
def execute(self): station = self.station platform = station.platform while True: for berth in range(0, len(station.berth_queues)): queue = station.berth_queues[berth] if len(queue) is 0: p = Person(interval=interval) p.behaviors = [Arrive()] p.position = vec3(platform[0].x + 2, platform[0].y - PRT.berth_length / 2 - berth * PRT.berth_length) p.destination = vec3(platform[0].x + 0.5, platform[0].y - PRT.berth_length / 2 - berth * PRT.berth_length) p.velocity = vec3(-0.1, 0.0) activate(p, p.move(), 0.0) queue.append(p) yield hold, self, 0.01
def calculate(self, boid): waypoints = boid.waypoints if len(waypoints) == 0: boid.arrived = True return vec3() displacement = waypoints[0] - boid.position if displacement.length() < 2: del waypoints[0] desired_velocity = displacement.normalize() * boid.desired_speed return desired_velocity - boid.velocity
def execute(self): waypoints = self.waypoints tk = world().tk while True: for person in self.people: if person.position[1] > 25: start_angle = uniform(0, pi) xx, yy = cos(start_angle) * 25 + 12.5, 21.0 - person.radius * 1.2 - sin(start_angle) * 25 person.position = vec3(xx, yy) person.waypoints = waypoints[0:] yield hold, self, 0.1
def random_people(cx, cy, dstx, dsty, cluster_size, interval, people): def random_position(): range = cluster_size * (pi * Person.radius**2 + 0.2) offset = range / 2 return random() * range - offset for ii in range(0, cluster_size): p = Person(interval) p.behaviors = [Arrive(), Separation()] try_again = True while try_again: px, py = cx + random_position(), cy + random_position() try_again = False for person in people: jx, jy, unused_z = person.position if sqrt((jx-px)**2 + (jy-py)**2) < Person.radius*2.5: try_again = True p.position = vec3(px, py) p.destination = vec3(dstx, dsty) activate(p, p.move(), 0.0) people.append(p)
def queue_steering_mind(boid): """Sum of all steering vectors, except Separation in some cases. The Separation steering vector will be ignored if any prior steering behavior gave a non-zero acceleration, typically Containment.""" acceleration = vec3() for behavior in boid.behaviors: if not isinstance(behavior, Separation) or acceleration.length() < 0.0001: acceleration += behavior.calculate(boid) return acceleration
def person_at_berth(self, person, berth): self.view_queues[berth].remove(person) self.berth_queues[berth].append(person) person.behaviors = [Arrive()] person.manager = None pp = self.platform person.destination = vec3( pp[0].x + 0.5 + (len(self.berth_queues[berth]) - 1) * person.radius * 2 * 1.2, pp[0].y - PRT.berth_length / 2 - berth * PRT.berth_length, ) person.world.tk.canvas.itemconfig(person.graphic, outline="red") return DONT_PASSIVATE
def calculate(self, boid): pdb.set_trace() the_world = boid.world others = the_world.boids(boid, 6.0) separation_distance = 6.0 * boid.velocity.length() / boid.max_speed acceleration = vec3() for other in others: local_position = the_world.to_local(boid, other.position) in_front = local_position[1] > -boid.radius if in_front and local_position.length() < separation_distance: separation = other.position - boid.position force = separation.scale(-1 / separation.length() ** 2) acceleration += force return acceleration
def generate(self): while True: start = uniform(5, 40) p = Person(interval=interval) p.behaviors = [Seek(), Separation()] p.position = vec3(100.0, start) platform_position = start * 8 / 199 p.destination = self.destination1.copy() p.manager = self.station1.person_at_station p.manager_args = [] activate(p, p.move(), 0.0) yield hold, self, 3.5
def main(testing='two_clumps', cluster_size=20): interval = 0.1 world(width=25, height=25, scale=25) initialize() xx = 12.5 people = [] p = Person(interval) p.behaviors = [Arrive(), Separation()] p.position = vec3(xx, 4.0) p.destination = vec3(xx, 21.0) people.append(p) activate(p, p.move(), 0.0) if testing == 'solo': pass if testing == 'immovable object': p = Person(interval) p.behaviors = [Arrive(), Separation()] p.position = vec3(xx - 0.08, 14.0) p.destination = vec3(xx - 0.08, 14.0) people.append(p) p.update() world().update_boid(p) # DON'T activate(p, p.move(), 0.0) if testing in ('clump', 'two clumps'): random_people(xx, 21.0, xx, 4.0, cluster_size, interval, people) if testing == 'two clumps': random_people(xx, 4.0, xx, 21.0, cluster_size, interval, people) u = Updater(interval) activate(u, u.execute(), 0.0) simulate(until=240)
def main(cluster_size=30): interval = 0.1 the_world = world(width=25, height=25, scale=25) initialize() xx = 12.5 door_width = 4 corner_size = 1 people = [] waypoints = [vec3(xx, 21.0), vec3(xx, 22.0), vec3(xx, 23.0), vec3(xx, 40.0)] people = random_people(xx, 4.0, waypoints, cluster_size, interval, people) tk = the_world.tk canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='moccasin') for wall in ( ( (-100, 21.0), (12.5 - door_width / 2 - corner_size, 21.0), (12.5 - door_width / 2, 21.0 + corner_size), (12.5 - door_width / 2, 100) ), ( (12.5 + door_width / 2, 100), (12.5 + door_width / 2, 21.0 + corner_size), (12.5 + door_width / 2 + corner_size, 21.0), (100, 21.0) ), ): points = [] for point in wall: points.append(x_(point[0])) points.append(y_(point[1])) canvas.create_polygon(points, fill='gray', outline='black') for ii in range(0, len(wall)-1): the_world.add_wall(wall[ii], wall[ii+1]) restarter = Restarter(people, waypoints) activate(restarter, restarter.execute(), 0.0) u = Updater(interval) activate(u, u.execute(), 0.0) simulate(until=10000)
def main(cluster_size=20): interval = 0.1 the_world = world(width=25, height=25, scale=25) initialize() xx = 12.5 p = Person(interval) p.behaviors = [Wander(), Separation(), Containment()] p.position = vec3(12.5, 12.5) p.destination = vec3(-100, 100) activate(p, p.move(), 0.0) people = [p] tk = the_world.tk canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='moccasin') for wall in ( ( (-100, 14.5), (10.5, 14.5), (10.5, 100) ), ( (10.5, -100), (10.5, 8.5), (8.5, 10.5), (-100, 10.5) ), ( (14.5, 100), (14.5, 14.5), ( 100, 14.5) ), ( ( 100, 10.5), (16.5, 10.5), (14.5, 8.5), (14.5, -100) ), ): points = [] for point in wall: points.append(x_(point[0])) points.append(y_(point[1])) canvas.create_polygon(points, fill='gray', outline='black') for ii in range(0, len(wall)-1): the_world.add_wall(wall[ii], wall[ii+1]) restarter = Restarter(people) activate(restarter, restarter.execute(), 0.0) u = Updater(interval) activate(u, u.execute(), 0.0) simulate(until=10000)
def __init__(self, mode, platform_center_y, doorway_width, prt_station, rail_x, headway): Process.__init__(self) self.world = world() self.mode = mode self.platform_center_y = platform_center_y self.doorway_width = doorway_width self.prt_station = prt_station self.rail_x = rail_x self.headway = headway self.rail_waypoints = [] self.rail_position = [] self.rail_destination = [] self.rows = 3 self.columns = 2 self.compactness = 1.2 if self.rows > 6 or self.columns > 4: self.compactness = 0.8 rx = self.rail_x railside_x = rx - Railcar.width / 2 outside_x = rx + Railcar.width / 2 top_rail_stop = platform_center_y + Railcar.length / 2 + 0.5 for kk in (0, 1): position = -140 - (Railcar.length + 1) * kk destination = top_rail_stop - (Railcar.length + 1) * kk self.rail_position.append(position) self.rail_destination.append(destination) top = destination + Railcar.length / 2 bottom = destination - Railcar.length / 2 self.world.add_wall( (railside_x, top), (outside_x, top), (outside_x, bottom), (railside_x, bottom) ) rail_waypoints = [] for ii in range(0, len(Railcar.doors)): rail_waypoints.append( [vec3(railside_x, top - Railcar.doors[ii]), vec3(rx - 3.5, top - Railcar.doors[ii])] ) self.rail_waypoints.append(rail_waypoints) print "passegers transferring:", self.rows * self.columns * len(Railcar.doors) * 2
def calculate(self, boid): the_world = boid.world position = boid.position radius = boid.radius for other in the_world.boids(boid): offset = position - other.position distance = offset.length() radius_ij = radius + other.radius if distance < radius_ij: offset = offset.scale(radius_ij - distance) boid.position += offset wall_found = False checked = [] for obstacle in the_world.obstacles(boid): if obstacle in checked: continue checked.append(obstacle) intersect, distance_to_line, normal = self.distance_from_line( position, obstacle) if intersect and distance_to_line < radius * 1.2: wall_found = True normal = normal.scale(radius * 1.2 - distance_to_line) boid.position += normal if not wall_found: checked = [] for obstacle in the_world.obstacles(boid): if obstacle in checked: continue checked.append(obstacle) for point in (obstacle[0], obstacle[1]): offset = position - vec3(point) distance = offset.length() if distance < radius * 1.2: boid.position += offset.scale(radius * 1.2 - distance) return vec3()
def __init__(self, interval=0.5,roomId=0, L=[]): Process.__init__(self) self.L = L self.world = world() self.interval = interval self.manager = None self.manager_args = [] self.waypoints = [] self.roomId = roomId self.position = vec3() self.velocity = vec3() self.localx = vec3(1, 0) self.localy = vec3(0, 1) self.world.add_boid(self) # from Helbing, et al "Self-organizing pedestrian movement" self.max_speed = normalvariate(1.36, 0.26) self.desired_speed = self.max_speed self.radius = normalvariate(self.average_radius, 0.025) / 2 self.intersection = vec3() self.arrived = False self.behaviors = [] self.steering_mind = default_steering_mind self.cancelled = 0 self.endpoint = True
def generate(self): """ creates a Person at the same time and same relative place on each of the PRT and LRT lines. """ prt_platform_length = self.p1_y2 - self.p1_y1 rail_platform_length = self.r_y2 - self.r_y1 people = 0 # http://findarticles.com/p/articles/mi_m1215/is_9_204/ai_108788436 event_max = 5000 while people < event_max: people += 1 if (people % 100) == 0: print "people: ", people start = uniform(0, 100) if start < 33.33: p = Person(interval=interval) p.behaviors = [Seek(), Separation()] p.manager_args = [] if start < 16.66: p_start = self.p1_y1 + start * 6 * prt_platform_length / 100 p.position = vec3(self.p1_x, p_start) platform_position = (p_start - self.p1_y1) * 0.7 p.destination = vec3(28., self.p1_y1 + 4 + platform_position) p.manager = self.prt_station1.person_at_station else: p_start = self.p2_y1 + (start - 16.66) * 6 * prt_platform_length / 100 p.position = vec3(self.p2_x, p_start) platform_position = (p_start - self.p2_y1) * 0.7 p.destination = vec3(28., self.p2_y1 + 4 + platform_position) p.manager = self.prt_station2.person_at_station activate(p, p.move(), 0.0) p = Person(interval=interval) p.behaviors = [Seek(), Separation()] p.position = vec3(self.r_x, self.r_y1 + 12 + start * 0.6 * rail_platform_length / 100) platform_position = start * (self.r_y2 - self.r_y1) / 100 p.destination = vec3(78., self.r_y1 + platform_position) p.manager = self.rail_station.person_at_platform p.manager_args = [] activate(p, p.move(), 0.0) yield hold, self, 0.25 yield passivate, self
def main(mode='path'): interval = 0.1 the_world = world(width=25, height=25, scale=25) initialize() xx = 12.5 door_width = 3.0 corner_size = 1 waypoints = [vec3(xx, 4.0), vec3(xx, 5.0), vec3(xx, 6.0), vec3(xx, 40.0)] tk = the_world.tk canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='blue') # stairs are added here so the graphics appear below the walls if mode == 'stairs': steps = 12 step_length = 0.28 zone = Stairs(lower_left=vec3(xx - door_width / 2, 7), upper_right=vec3(xx + door_width / 2, 7 + steps * step_length)) the_world.add_zone(zone) zone.draw() wall1 = ( (-100, 5.0), (12.5 - door_width / 2 - corner_size, 5.0), (12.5 - door_width / 2, 5.0 + corner_size), (12.5 - door_width / 2, 100) ) wall2 = ( (12.5 + door_width / 2, 100), (12.5 + door_width / 2, 5.0 + corner_size), (12.5 + door_width / 2 + corner_size, 5.0), (100, 5.0) ) wall3 = ( (12,10),(13,10),(13,11),(12,11) ) for wall in ( wall1 , wall2 ,wall3 ): points = [] for point in wall: points.append(x_(point[0])) points.append(y_(point[1])) canvas.create_polygon(points, fill='red', outline='black') for ii in range(0, len(wall)-1): the_world.add_wall(wall[ii], wall[ii+1]) pg = PersonGenerator() activate(pg, pg.generate(interval, waypoints), 0.0) u = Updater(interval) activate(u, u.execute(), 0.0) SimPy.Simulation.simulate(until=100)
def random_people(cx, cy, waypoints, cluster_size, interval, people): def random_position(): range = cluster_size * (pi * Person.average_radius**2 + 0.2) offset = range / 2 return uniform(0.0, range) - offset for ii in range(0, cluster_size): p = Person(interval) p.behaviors = [Containment(), Separation(), Queuing(), FollowWaypoints()] p.steering_mind = queue_steering_mind try_again = True while try_again: px, py = cx + random_position(), cy + random_position() if py > (21.0 - Person.radius): continue try_again = False for person in people: jx, jy, unused_z = person.position if sqrt((jx-px)**2 + (jy-py)**2) < Person.average_radius*2.5: try_again = True p.position = vec3(px, py) p.waypoints = waypoints[0:] activate(p, p.move(), 0.0) people.append(p) return people
rsm = RailStationManager() rsm.destination_x = 30.0 activate(rsm, rsm.check(), 0.0) pg = PersonGenerator(psm1, psm2, rsm) activate(pg, pg.generate(), 0.0) s1 = Straight((70.0, -30.0), (70.0, 5.0)) s1.next, last_left, last_right, length = station((70.0, 5.0), PRT.max_speed, "right", 3, psm1) last_left.next = last_right.next = s2 = Straight((70.0, 5.0 + length), (70.0, 125.0)) psm1.mainline = last_left s2.next, last_left, last_right, length = station((70.0, 125.0), PRT.max_speed, "right", 3, psm2) last_left.next = last_right.next = s7 = Straight((70.0, 125.0 + length), (70.0, 10000.0)) psm2.mainline = last_left prt_draw(s1, 70.0, -31.0) pg.destination1 = vec3(s1.next.destinations[0].x + 2.2, s1.next.destinations[0].y) pg.destination2 = vec3(s2.next.destinations[0].x + 2.2, s2.next.destinations[0].y) rg = RailcarGenerator(rsm) activate(rg, rg.generate(), 0.0) tg = PRTGenerator() activate(tg, tg.generate(s1, interval), 0.0) u = Updater(interval) activate(u, u.execute(), 0.0) simulate(until=1000) # simulate(until=400)
def to_local(self, boid, point): xx, yy, unused_z = point - boid.position return vec3(boid.localy.y * xx - boid.localy.x * yy, -boid.localx.y * xx + boid.localx.x * yy)
p.manager = self.station1.person_at_station p.manager_args = [] activate(p, p.move(), 0.0) yield hold, self, 3.5 if __name__ == '__main__': initialize() berths = 10 psm1 = PRTStationManager(berths) activate(psm1, psm1.check(), 0.0) pg = PersonGenerator(psm1) activate(pg, pg.generate(), 0.0) s1 = Straight((70., -30.), (70., 5.0)) s1.next, last_left, last_right, length = station((70.0, 5.0), PRT.max_speed, 'right', berths, psm1) last_left.next = last_right.next = s2 = Straight((70.0, 5.0 + length), (70., 10000.0)) psm1.mainline = last_left prt_draw(s1, 70.0, -31.0) pg.destination1 = vec3(s1.next.destinations[0].x + 8, (s1.next.platform[0].y + s1.next.platform[1].y) / 2) tg = PRTGenerator() activate(tg, tg.generate(s1, interval, percent_empty=0.60), 0.0) u = Updater(interval) activate(u, u.execute(), 0.0) simulate(until=1000) #simulate(until=400)
def move(self): """ Gr : Graph of rooms """ while True: while self.cancelled: yield passivate, self print "Person.move: activated after being cancelled" checked = [] for zone in self.world.zones(self): if zone not in checked: checked.append(zone) zone(self) acceleration = self.steering_mind(self) acceleration = acceleration.truncate(self.max_acceleration) self.acceleration = acceleration velocity = self.velocity + acceleration * self.interval self.velocity = velocity.truncate(self.max_speed) if velocity.length() > 0.2: # record direction only when we've really had some self.localy = velocity.normalize() self.localx = vec3(self.localy.y, -self.localy.x) self.position = self.position + self.velocity * self.interval self.update() self.world.update_boid(self) if self.arrived: self.arrived = False if self.endpoint: self.endpoint = False # # Si porte on continue # # # ig destination --> next room # adjroom = self.L.Gr.neighbors(self.roomId) Nadjroom = len(adjroom) k = int(np.floor(uniform(0,Nadjroom))) nextroom = adjroom[k] p_nextroom = self.L.Gr.pos[nextroom] setdoors1 = self.L.Gr.node[self.roomId]['doors'] setdoors2 = self.L.Gr.node[nextroom]['doors'] doorId = np.intersect1d(setdoors1,setdoors2)[0] # # coord door # unode = self.L.Gs.neighbors(doorId) p1 = self.L.Gs.pos[unode[0]] p2 = self.L.Gs.pos[unode[1]] print p1 print p2 pdoor = (np.array(p1)+np.array(p2))/2 self.destination = vec3(pdoor[0],pdoor[1]) waittime = uniform(0,10) if self.manager: if self.manager(self, *self.manager_args): yield hold , self , waittime else: yield hold, self , waittime else: #ptemp = np.array(self.position-p_nextroom) #dtemp = np.sqrt(np.dot(ptemp,ptemp)) #if dtemp < 0.1: self.endpoint = True self.roomId = nextroom # else: self.destination=vec3(p_nextroom[0],p_nextroom[1]) yield hold, self, self.interval else: yield hold, self, self.interval
def copy(self): return vec3(self)