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.))]
评论列表
文章目录