simulation_object.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:kuramoto_vicsek 作者: lisamnash 项目源码 文件源码
def calc_vbar(self):
        # Calculates the average velocities from neighboring birds depending on max_dist and max_num.
        my_tree = spatial.cKDTree(self.current_points)
        dist, indexes = my_tree.query(self.current_points, k=self._max_num)

        ri = np.zeros((len(self.current_points), self._max_num), dtype=int)
        rk = np.zeros_like(ri, dtype=int)

        good_inds = (dist < self._max_dist)
        ri[good_inds] = indexes[good_inds]
        rk[good_inds] = 1

        # I should get the angle and average
        ori = np.arctan2(self.current_v[:, 1], self.current_v[:, 0])

        mean_n = []
        for i in range(len(ri)):
            nei = ri[i][np.where(rk[i] == 1)[0]]
            mm = (np.arctan2(np.sum(np.sin(ori[nei])), np.sum(np.cos(ori[nei])))) % (2 * np.pi)
            mean_n.append(mm)

        vbar = np.array(zip(np.cos(mean_n), np.sin(mean_n)))
        return vbar, [np.array(ri), np.array(rk)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号