示例#1
0
 def angle_arrow(self, path, origin='head'):
     ''' Compute the two points of the arrow head with the right angle '''
     if origin == 'tail':
         path = path.toReversed()
     length = path.length()
     percent = path.percentAtLength(length - 10.0)
     src = path.pointAtPercent(percent)
     #path.moveTo(path.pointAtPercent(1))
     end_point = path.pointAtPercent(1)
     #end_point = path.currentPosition()
     line = QLineF(src, end_point)
     angle = math.acos(line.dx() / (line.length() or 1))
     if line.dy() >= 0:
         angle = math.pi * 2 - angle
     arrow_size = 10.0
     arrow_p1 = end_point + QPointF(
         math.sin(angle - math.pi / 3) * arrow_size,
         math.cos(angle - math.pi / 3) * arrow_size)
     arrow_p2 = end_point + QPointF(
         math.sin(angle - math.pi + math.pi / 3) * arrow_size,
         math.cos(angle - math.pi + math.pi / 3) * arrow_size)
     return (arrow_p1, arrow_p2)
示例#2
0
 def angle_arrow(self, path, origin='head'):
     ''' Compute the two points of the arrow head with the right angle '''
     if origin == 'tail':
         path = path.toReversed()
     length = path.length()
     percent = path.percentAtLength(length - 10.0)
     src = path.pointAtPercent(percent)
     #path.moveTo(path.pointAtPercent(1))
     end_point = path.pointAtPercent(1)
     #end_point = path.currentPosition()
     line = QLineF(src, end_point)
     angle = math.acos(line.dx() / (line.length() or 1))
     if line.dy() >= 0:
         angle = math.pi * 2 - angle
     arrow_size = 10.0
     arrow_p1 = end_point + QPointF(
             math.sin(angle - math.pi / 3) * arrow_size,
             math.cos(angle - math.pi / 3) * arrow_size)
     arrow_p2 = end_point + QPointF(
             math.sin(angle - math.pi + math.pi / 3) * arrow_size,
             math.cos(angle - math.pi + math.pi / 3) * arrow_size)
     return (arrow_p1, arrow_p2)