Exemple #1
0
    def _get_force(self):
        forces = np.zeros((self.peds.size(), 2))
        vision_angle = self.config("fov_phi", 100.0)
        directions, _ = stateutils.desired_directions(self.peds.state)
        if self.peds.has_group():
            for group in self.peds.groups:
                group_size = len(group)
                # 1-agent groups don't need to compute this
                if group_size <= 1:
                    continue
                member_pos = self.peds.pos()[group, :]
                member_directions = directions[group, :]
                # use center of mass without the current agent
                relative_com = np.array(
                    [
                        stateutils.center_of_mass(member_pos[np.arange(group_size) != i, :2])
                        - member_pos[i, :]
                        for i in range(group_size)
                    ]
                )

                com_directions, _ = stateutils.normalize(relative_com)
                # angle between walking direction and center of mass
                element_prod = np.array(
                    [np.dot(d, c) for d, c in zip(member_directions, com_directions)]
                )
                com_angles = np.degrees(np.arccos(element_prod))
                rotation = np.radians(
                    [a - vision_angle if a > vision_angle else 0.0 for a in com_angles]
                )
                force = -rotation.reshape(-1, 1) * member_directions
                forces[group, :] += force

        return forces * self.factor
Exemple #2
0
    def _get_force(self):
        forces = np.zeros((self.peds.size(), 2))
        directions, dist = stateutils.desired_directions(self.peds.state)
        if self.peds.has_group():
            for group in self.peds.groups:
                group_size = len(group)
                # 1-agent groups don't need to compute this
                if group_size <= 1:
                    continue
                member_pos = self.peds.pos()[group, :]
                member_directions = directions[group, :]
                member_dist = dist[group]
                # use center of mass without the current agent
                relative_com = np.array(
                    [
                        stateutils.center_of_mass(member_pos[np.arange(group_size) != i, :2])
                        - member_pos[i, :]
                        for i in range(group_size)
                    ]
                )

                com_directions, com_dist = stateutils.normalize(relative_com)
                # angle between walking direction and center of mass
                element_prod = np.array(
                    [np.dot(d, c) for d, c in zip(member_directions, com_directions)]
                )
                force = (
                    com_dist.reshape(-1, 1)
                    * element_prod.reshape(-1, 1)
                    / member_dist.reshape(-1, 1)
                    * member_directions
                )
                forces[group, :] += force

        return forces * self.factor
Exemple #3
0
 def _get_force(self):
     forces = np.zeros((self.peds.size(), 2))
     if self.peds.has_group():
         for group in self.peds.groups:
             threshold = (len(group) - 1) / 2
             member_pos = self.peds.pos()[group, :]
             com = stateutils.center_of_mass(member_pos)
             force_vec = com - member_pos
             vectors, norms = stateutils.normalize(force_vec)
             vectors[norms < threshold] = [0, 0]
             forces[group, :] += vectors
     return forces * self.factor
Exemple #4
0
 def _get_force(self):
     forces = np.zeros((self.peds.size(), 2))
     if self.peds.has_group():
         for group in self.peds.groups:
             threshold = (len(group) - 1) / 2
             member_pos = self.peds.pos()[group, :]
             com = stateutils.center_of_mass(member_pos)
             force_vec = com - member_pos
             norms = stateutils.speeds(force_vec)
             softened_factor = (np.tanh(norms - threshold) + 1) / 2
             forces[group, :] += (force_vec.T * softened_factor).T
     return forces * self.factor