geometry.py 文件源码

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

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def move_forward_center_discrete(distance, center, straight = True):
  """Move worm forward peristaltically

  Arguments:
    distance (float): distance to move forward
    center (nx2 array): center points
    length (float or None): length to use for position update
    straight (bool): if True extrapolated points move straight

  Note:
    The head is first point in center line and postive distances will move the
    worm in this direction.
  """  
  cinterp, u = splprep(center.T, u = None, s = 0, per = 0)
  us = u - distance;
  x, y = splev(us, cinterp, der = 0); 
  cline2 = np.array([x,y]).T;   

  if straight:
     l = length_from_center_discrete(center);
     if distance > 0:
       idx = np.where(us < 0)[0];
       if len(idx) > 0:
         d = center[0,:] - center[1,:];
         d = d / np.linalg.norm(d) * l;
         for i in idx:
           cline2[i,:] = center[0,:] - d * us[i];
     elif distance < 0:
       idx = np.where(us > 1)[0];
       if len(idx) > 0:
         d = center[-1,:] - center[-2,:];
         d = d / np.linalg.norm(d) * l;
         for i in idx:
           cline2[i,:] = center[-1,:] + d * (us[i]-1);

  return cline2;
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号