Esempio n. 1
0
 def cohesion(self, neighbor_center):
     """
     Function to move the agent towards the center of mass of its neighbors
     :param neighbor_rotation: np.array(x,y)
     """
     force = neighbor_center - self.pos
     return helperfunctions.normalize(force - self.v)
Esempio n. 2
0
    def avoid_obstacle(self, obstacle_center, obstacle_outside):
        """
        Function to avoid obstacles
        need to take into account whether agents inside/outside the obstacle
        moves the agent away from the boarder by distance equivalent to its size
        :param obstacle_center: tuple (int,int), the center coordinates of the obstacle
        :param obstacle_outside: boolean, defines whether the agents are inside or outside of the obstacle
        """
        x, y = self.mask.get_size()  #get the size of the boid
        x_ob, y_ob = obstacle_center

        if obstacle_outside:  #agents outside the obstacle
            if self.pos[0] >= x_ob:
                self.pos[0] += x
            else:
                self.pos[0] -= x

            if self.pos[1] >= y_ob:
                self.pos[1] += y
            else:
                self.pos[1] -= y
        else:  #agents inside the obstacle:
            if self.pos[0] <= x_ob:
                self.pos[0] += x
            else:
                self.pos[0] -= x

            if self.pos[1] <= y_ob:
                self.pos[1] += y
            else:
                self.pos[1] -= y

        #adjust the velocity by rotating it around
        self.v = (helperfunctions.rotate(helperfunctions.normalize(self.v)) *
                  helperfunctions.norm(self.v))
Esempio n. 3
0
 def avoid_obstacle(self):
     """
     Function to avoid obstacles
     need to take into account whether agents inside/outside the obstacle
     moves the agent away from the boarder by distance equivalent to its size
     """
     #adjust the velocity by rotating it around
     self.v = (helperfunctions.rotate(helperfunctions.normalize(self.v)) *
               helperfunctions.norm(self.v))
     self.pos += self.v * 1.5
Esempio n. 4
0
 def wander(self, wander_dist, wander_radius, wander_angle):
     """
     Function to make the agents to perform random movement
     """
     rands = 2 * np.random.rand() - 1
     cos = np.cos(self.wandering_angle)
     sin = np.sin(self.wandering_angle)
     n_v = helperfunctions.normalize(self.v)
     circle_center = n_v * wander_dist
     displacement = np.dot(np.array([[cos, -sin], [sin, cos]]),
                           n_v * wander_radius)
     wander_force = circle_center + displacement
     self.wandering_angle += wander_angle * rands
     return wander_force
Esempio n. 5
0
 def align(self, neighbor_force):
     """
     Function to align the agent in accordance to neighbor velocity
     :param neighbor_force: np.array(x,y)
     """
     return helperfunctions.normalize(neighbor_force - self.v)