def init(self): if self.parameter is None: self.parameter = 0 self.agent.position = Vec2d(10, 10) self.agent.goal = Vec2d(*self.world.size) - self.agent.position self.agent.angle = (self.agent.goal - self.agent.position).angle() rects = [] for j in xrange(2): for i in xrange(4): r = obstacle.Rectangle((i + 1) * 50 + 100 * i, (j + 1) * 100 + 120 * j - 50, 100, 120) rects.append(r) self.world.add_obstacle(r) for i in xrange(self.parameter): good = False u = RandomWalkingAvoider() while not good: # generate random positions for pedestrians that are not inside obstacles... init_position = Vec2d(random.randrange(u.radius + 1, self.world.size[0] - u.radius - 1), random.randrange(u.radius + 1, self.world.size[1] - u.radius - 1)) good = init_position.distance_to(self.agent.position) > 20 for r in rects: if not good: break good = good and not r._rect.inflate(u.radius * 3, u.radius * 3).collidepoint(init_position) u.position = init_position self.world.add_unit(u)
def init(self): if self.parameter is None: self.parameter = 10 self.agent.position = Vec2d(200, 200) self.agent.goal = Vec2d(400, 200) self.agent.angle = 0 shapes = [ [ Vec2d(100, 100), Vec2d(100, 380), Vec2d(500, 380), Vec2d(500, 100), Vec2d(100, 100), ], [ Vec2d(300, 100), Vec2d(300, 250), ], [ Vec2d(200, 250), Vec2d(400, 250), ] ] for shape in shapes: last = shape[0] for point in shape: self.world.add_obstacle(obstacle.Line(last, point)) last = point for m in xrange(self.parameter): good = False u = RandomWalkingAvoider(random_seed=self.random.random()) # generate random positions for pedestrians # that are not inside obstacles... while not good: init_position = Vec2d( self.random.randrange(100 + u.radius + 1, 500 - u.radius - 1), self.random.randrange(100 + u.radius + 1, 380 - u.radius - 1), ) good = init_position.distance_to(self.agent.position) > 20 for shape in shapes: last = shape[0] for point in shape: if linesegdist2( last, point, init_position ) < u.radius ** 2: good = False break last = point if not good: break u.position = init_position self.world.add_unit(u)
def init(self): if self.parameter is None: self.parameter = 50 # start is upper left corner self.agent.position = Vec2d(10, 10) # goal is lower right self.agent.goal = Vec2d(*self.world.size) - self.agent.position self.agent.angle = (self.agent.goal - self.agent.position).angle() for i in xrange(self.parameter): init_position = self.agent.position while init_position.distance_to(self.agent.position) < 20: init_position = Vec2d(self.random.randrange(self.world.size[0]), self.random.randrange(self.world.size[1])) u = RandomWalkingAvoider(self.random.random()) u.position = init_position self.world.add_unit(u)
def init(self): if parameter is None: parameter = 50 self.agent.position = Vec2d(200, 200) self.agent.goal = Vec2d(400, 200) self.agent.angle = 0 self.world.add_obstacle( obstacle.Line(Vec2d(100, 100), Vec2d(100, 300)) ) self.world.add_obstacle( obstacle.Line(Vec2d(100, 300), Vec2d(500, 300)) ) self.world.add_obstacle( obstacle.Line(Vec2d(500, 300), Vec2d(500, 100)) ) self.world.add_obstacle( obstacle.Line(Vec2d(500, 100), Vec2d(100, 100)) ) self.world.add_obstacle( obstacle.Line(Vec2d(300, 100), Vec2d(300, 250)) ) for m in xrange(parameter): good = False u = RandomWalkingAvoider() # generate random positions for pedestrians # that are not inside obstacles... while not good: init_position = Vec2d( random.randrange(u.radius + 1, self.world.size[0] - u.radius - 1), random.randrange(u.radius + 1, self.world.size[1] - u.radius - 1) ) good = init_position.distance_to(self.agent.position) > 20 u.position = init_position self.world.add_unit(u)