569qreal QLineF::angle()
const
571 const qreal dx = pt2.x() - pt1.x();
572 const qreal dy = pt2.y() - pt1.y();
574 const qreal theta = qRadiansToDegrees(qAtan2(-dy, dx));
576 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
578 if (qFuzzyCompare(theta_normalized, qreal(360)))
581 return theta_normalized;
618QLineF QLineF::fromPolar(qreal length, qreal angle)
620 const qreal angleR = qDegreesToRadians(angle);
621 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
631QLineF QLineF::unitVector()
const
633 const qreal x = dx();
634 const qreal y = dy();
636 const qreal len = qHypot(x, y);
637 QLineF f(p1(), QPointF(pt1.x() + x / len, pt1.y() + y / len));
640 if (qAbs(f.length() - 1) >= 0.001)
641 qWarning(
"QLine::unitVector: New line does not have unit length");
658QLineF::IntersectionType QLineF::intersects(
const QLineF &l, QPointF *intersectionPoint)
const
661 const QPointF a = pt2 - pt1;
662 const QPointF b = l.pt1 - l.pt2;
663 const QPointF c = pt1 - l.pt1;
665 const qreal denominator = a.y() * b.x() - a.x() * b.y();
666 if (denominator == 0 || !qt_is_finite(denominator))
667 return NoIntersection;
669 const qreal reciprocal = 1 / denominator;
670 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;
671 if (intersectionPoint)
672 *intersectionPoint = pt1 + a * na;
674 if (na < 0 || na > 1)
675 return UnboundedIntersection;
677 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;
678 if (nb < 0 || nb > 1)
679 return UnboundedIntersection;
681 return BoundedIntersection;