本文整理汇总了Python中PyQt4.QtCore.QLineF.dx方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.dx方法的具体用法?Python QLineF.dx怎么用?Python QLineF.dx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.dx方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crop_line
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import dx [as 别名]
def crop_line(self, line, line_point):
global_rect = self.globalBoundingRect()
# Go to local coordinate system - ellipse equations assume ellipse is centered on (0,0)
local_trans = global_rect.center()
local_line = QLineF(line.p1() - local_trans, line.p2() - local_trans)
if(local_line.dx() == 0):
return line
# Solve line equation
e_a = ((local_line.p2().y() - local_line.p1().y()) /
(local_line.p2().x() - local_line.p1().x()))
e_b = local_line.p1().y() - e_a * local_line.p1().x()
# ellipse params
e_c = global_rect.width()/2
e_d = global_rect.height()/2
# check condition
if(e_c * e_d == 0):
return line
# precalculate things that are used more than once
# a^2, b^2 ...
ak = math.pow(e_a, 2)
bk = math.pow(e_b, 2)
ck = math.pow(e_c, 2)
dk = math.pow(e_d, 2)
# check another condition
if((ak * ck + dk) == 0):
return line
# a^2*c^2, c^2*d^2
akck = ak * ck
ckdk = ck * dk
# a*b*c^2
abck = e_a*e_b*ck
# parts of denomiator and numerator of x
denom = (akck + dk)
numer = math.sqrt(ck*dk*(akck-bk+dk))
# Decide which points to take
xrel = (line.p1().x() > line.p2().x())
yrel = (line.p1().y() > line.p2().y())
if(line_point != 0):
xrel = not xrel
yrel = not yrel
if((xrel and yrel) or (xrel and not yrel)):
x1 = (-numer - abck) / denom
y1 = (e_b*dk - e_a*math.sqrt(-ckdk*(-akck+bk-dk))) / denom
intersectionPoint = QPointF(x1, y1)
elif((not xrel and yrel) or (not xrel and not yrel)):
x2 = (numer - abck) / denom
y2 = -(e_b*dk - e_a*math.sqrt(-ckdk*(-akck+bk-dk))) / denom
intersectionPoint = QPointF(x2, y2)
# Go back to global coordinate system
intersectionPoint = intersectionPoint + local_trans
if(line_point == 0):
return QLineF(intersectionPoint, line.p2())
else:
return QLineF(line.p1(), intersectionPoint)
return line