本文整理汇总了Python中PyQt5.QtCore.QLineF.intersect方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.intersect方法的具体用法?Python QLineF.intersect怎么用?Python QLineF.intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.intersect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import intersect [as 别名]
def paint(self, painter, option, widget=None):
if self.my_start_item.collidesWithItem(self.my_end_item):
return
my_start_item = self.my_start_item
my_end_item = self.my_end_item
my_color = self.my_color
my_pen = self.pen()
my_pen.setColor(self.my_color)
arrow_size = 20.0
painter.setPen(my_pen)
painter.setBrush(my_color)
center_line = QLineF(my_start_item.pos(), my_end_item.pos())
end_polygon = my_end_item.polygon
p1 = end_polygon.first() + my_end_item.pos()
intersect_point = QPointF()
for i in end_polygon:
p2 = i + my_end_item.pos()
poly_line = QLineF(p1, p2)
intersect_type = poly_line.intersect(center_line, intersect_point)
if intersect_type == QLineF.BoundedIntersection:
break
p1 = p2
self.setLine(QLineF(intersect_point, my_start_item.pos()))
line = self.line()
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (math.pi * 2) - angle
arrow_p1 = line.p1() + QPointF(math.sin(angle + math.pi / 3.0) * arrow_size,
math.cos(angle + math.pi / 3) * arrow_size)
arrow_p2 = line.p1() + QPointF(math.sin(angle + math.pi - math.pi / 3.0) * arrow_size,
math.cos(angle + math.pi - math.pi / 3.0) * arrow_size)
self.arrowHead.clear()
for point in [line.p1(), arrow_p1, arrow_p2]:
self.arrowHead.append(point)
painter.drawLine(line)
painter.drawPolygon(self.arrowHead)
if self.isSelected():
painter.setPen(QPen(my_color, 1, Qt.DashLine))
my_line = QLineF(line)
my_line.translate(0, 4.0)
painter.drawLine(my_line)
my_line.translate(0, -8.0)
painter.drawLine(my_line)
示例2: intersectLineGeometry
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import intersect [as 别名]
def intersectLineGeometry(self, lineGeo, breakShape):
"""
Try to break lineGeo with the given breakShape. Will return the intersection points of lineGeo with breakShape.
"""
# TODO geos should be abs
intersections = []
line = QLineF(lineGeo.Ps.x, lineGeo.Ps.y, lineGeo.Pe.x, lineGeo.Pe.y)
for breakGeo in breakShape.geos.abs_iter():
if isinstance(breakGeo, LineGeo):
breakLine = QLineF(breakGeo.Ps.x, breakGeo.Ps.y, breakGeo.Pe.x, breakGeo.Pe.y)
intersection = QPointF(0, 0) # values do not matter
res = line.intersect(breakLine, intersection)
if res == QLineF.BoundedIntersection:
intersections.append(Point(intersection.x(), intersection.y()))
return intersections
示例3: intersection
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import intersect [as 别名]
def intersection(self, line):
"""
Returns the intersection of the shape with the given line (in scene coordinates).
:type line: QLineF
:rtype: QPointF
"""
intersection = QPointF()
path = self.painterPath()
polygon = self.mapToScene(path.toFillPolygon(self.transform()))
for i in range(0, polygon.size() - 1):
polyline = QLineF(polygon[i], polygon[i + 1])
if polyline.intersect(line, intersection) == QLineF.BoundedIntersection:
return intersection
return None
示例4: __findRectIntersectionPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import intersect [as 别名]
def __findRectIntersectionPoint(self, item, p1, p2):
"""
Private method to find the intersetion point of a line with a
rectangle.
@param item item to check against
@param p1 first point of the line (QPointF)
@param p2 second point of the line (QPointF)
@return the intersection point (QPointF)
"""
rect = self.__mapRectFromItem(item)
lines = [
QLineF(rect.topLeft(), rect.topRight()),
QLineF(rect.topLeft(), rect.bottomLeft()),
QLineF(rect.bottomRight(), rect.bottomLeft()),
QLineF(rect.bottomRight(), rect.topRight()),
]
intersectLine = QLineF(p1, p2)
intersectPoint = QPointF(0, 0)
for line in lines:
if intersectLine.intersect(line, intersectPoint) == QLineF.BoundedIntersection:
return intersectPoint
return QPointF(-1.0, -1.0)