angle.py 文件源码

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

项目:livespin 作者: biocompibens 项目源码 文件源码
def getRotation(self, plot = True):
        if self.nComponents != 3:
            raise Exception("ERROR : not 3 centers")
        ## choice only surface based criteria
        areas = np.zeros(self.nComponents)
        for i in xrange(self.nComponents):
            areas[i] = self.params[6*i+3]*self.params[6*i+4]*np.pi
        goodcenters = range(self.nComponents)
        other = np.argmax(areas)
        goodcenters.pop(other)
        x3 = self.params[6*other+1]
        y3 = self.params[6*other+2]
        x1 = self.params[6*goodcenters[0]+1]
        y1 = self.params[6*goodcenters[0]+2]
        x2 = self.params[6*goodcenters[1]+1]
        y2 = self.params[6*goodcenters[1]+2]
        cx = (x1 + x2)/2.
        cy = (y1 + y2)/2.
        rot = acos((cy-y3) /1./ self.euclidian_dist(x3, y3, cx, cy))
        if x3-cx < 0:
            rot = -1.*rot
        if plot:
            pylab.subplot(2,2,1)
            pylab.plot([y3, cy], [x3, cx], 'm-', label = (x3-cx)>0)
            pylab.plot(y3, x3, 'go', label = (y3-cy)>0)
            pylab.axhline(y = x3, c= 'y', ls = '--')
            pylab.plot([y1, y2], [x1, x2], 'r+')
            pylab.subplot(2,2,2)
            pylab.plot(self.rotation(x3, y3, rot)[1], self.rotation(x3, y3, rot)[0], 'go')
            pylab.plot(self.rotation(cx, cy, rot)[1], self.rotation(cx, cy, rot)[0], 'ro')
            pylab.plot([self.rotation(x1, y1, rot)[1], self.rotation(x2, y2, rot)[1]], [self.rotation(x1, y1, rot)[0], self.rotation(x2, y2, rot)[0]], 'r+')
            pylab.xlim([-50., 50.])
            pylab.ylim([-50., 50.])
        return rot, [(x1,y1), (x2,y2), (x3,y3), (int((x3+cx)/2.), int((y3+cy)/2.))]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号