curve.py 文件源码

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

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def theta(self, points = None, with_xy = True, with_length = True, with_orientation = True, reference = 0.5):
    """Returns a Spline representing the derivative of the tangent angle along a 2d curve

    Arguments:
      points (int, array or None): sample points used to determine theta
      with_lenth (bool): if True also return length of the curve
      with_position (bool): if True also return absolute position
      with_orientation (bool): if True also return absolute orientation of the curve
      reference (float): reference point for absolute position and orientation

    Returns:
      Spline: spline of theta

    Note:
      To fully reconstruct the curve, the center point, length and orientation is needed.
    """
    if self.ndim != 2:
      raise RuntimeError('theta angle can only be computed for 2d curves');

    points = self.get_points(points, error = 'cannot determine sample points needed for the calculation of theta');    

    #get the tangents  and tangent angles    
    tgs = splev(points, self.tck(), der = 1);
    tgs = np.vstack(tgs).T;
    phi = np.arctan2(tgs[:,1],tgs[:,0]);
    phi = np.mod(phi + np.pi, 2 * np.pi) - np.pi;
    #phi = Spline(phi, points = self.points, knots = self.knots, degree = self.degree + 1);
    tck = splrep(points, phi, s = 0.0, k = self.degree + 1);
    phi = Spline(tck = tck);

    orientation = phi(reference);
    theta = phi.derivative();

    rtr = [theta];
    if with_xy:
      rtr.append(self(reference));      
    if with_length:
      rtr.append(self.length());       
    if with_orientation:
      rtr.append(orientation);
    return tuple(rtr);
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号