565qreal QLineF::angle()
const
567 const qreal dx = pt2.x() - pt1.x();
568 const qreal dy = pt2.y() - pt1.y();
570 const qreal theta = qRadiansToDegrees(qAtan2(-dy, dx));
572 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
574 if (qFuzzyCompare(theta_normalized, qreal(360)))
577 return theta_normalized;
614QLineF QLineF::fromPolar(qreal length, qreal angle)
616 const qreal angleR = qDegreesToRadians(angle);
617 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
627QLineF QLineF::unitVector()
const
629 const qreal x = dx();
630 const qreal y = dy();
632 const qreal len = qHypot(x, y);
633 QLineF f(p1(), QPointF(pt1.x() + x / len, pt1.y() + y / len));
636 if (qAbs(f.length() - 1) >= 0.001)
637 qWarning(
"QLine::unitVector: New line does not have unit length");
654QLineF::IntersectionType QLineF::intersects(
const QLineF &l, QPointF *intersectionPoint)
const
657 const QPointF a = pt2 - pt1;
658 const QPointF b = l.pt1 - l.pt2;
659 const QPointF c = pt1 - l.pt1;
661 const qreal denominator = a.y() * b.x() - a.x() * b.y();
662 if (denominator == 0 || !qt_is_finite(denominator))
663 return NoIntersection;
665 const qreal reciprocal = 1 / denominator;
666 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;
667 if (intersectionPoint)
668 *intersectionPoint = pt1 + a * na;
670 if (na < 0 || na > 1)
671 return UnboundedIntersection;
673 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;
674 if (nb < 0 || nb > 1)
675 return UnboundedIntersection;
677 return BoundedIntersection;