def _edgePos(self, w=None): # returns handle position t = self.roi._homography n = self.roi.nCells if w is None: w = self.roi.width p = self.pos return t.map( QtCore.QPointF(((p[0] - w[1]) / n[1]), (p[1] - w[0]) / n[0]))
def _intersectionPointsAndAngles(r, ratioEllispeRectangle): ''' return all 8 x and y coords of lines build by intersection of ellipse and rect ''' w = r.width() h = r.height() x1 = 0.5 * w y2 = 0.5 * h #ellipse parameters: a = x1 * ratioEllispeRectangle b = y2 * ratioEllispeRectangle #intersection coords in the 1st quadrant with center=(0,0): y1 = ((1 - x1**2 / a**2) * b**2)**0.5 x2 = ((1 - y2**2 / b**2) * a**2)**0.5 c = r.center() cx = c.x() cy = c.y() #edge points: p1 = QtCore.QPointF(cx + x1, cy + y1) p2 = QtCore.QPointF(cx + x2, cy + y2) p3 = QtCore.QPointF(cx - x2, cy + y2) p4 = QtCore.QPointF(cx - x1, cy + y1) p5 = QtCore.QPointF(cx - x1, cy - y1) p6 = QtCore.QPointF(cx - x2, cy - y2) p7 = QtCore.QPointF(cx + x2, cy - y2) p8 = QtCore.QPointF(cx + x1, cy - y1) #angle in as degree*16 (needed in .drawArc) a1 = int(QtCore.QLineF(c, p1).angle() * 16) a2 = int(QtCore.QLineF(c, p2).angle() * 16) a4 = int(QtCore.QLineF(c, p4).angle() * 16) a6 = int(QtCore.QLineF(c, p6).angle() * 16) a8 = int(QtCore.QLineF(c, p8).angle() * 16) arc_length = a1 - a2 return (p1, p2, p3, p4, p5, p6, p7, p8), (a2, a4, a6, a8), arc_length
def homography(self): t = QtGui.QTransform() poly = QtGui.QPolygonF([QtCore.QPointF(*v) for v in self.vertices()]) QtGui.QTransform.squareToQuad(poly, t) self._homography = t return t