564qreal QLineF::angle()
const
566 const qreal dx = pt2.x() - pt1.x();
567 const qreal dy = pt2.y() - pt1.y();
569 const qreal theta = qRadiansToDegrees(qAtan2(-dy, dx));
571 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
573 if (qFuzzyCompare(theta_normalized, qreal(360)))
576 return theta_normalized;
613QLineF QLineF::fromPolar(qreal length, qreal angle)
615 const qreal angleR = qDegreesToRadians(angle);
616 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
626QLineF QLineF::unitVector()
const
628 const qreal x = dx();
629 const qreal y = dy();
631 const qreal len = qHypot(x, y);
632 QLineF f(p1(), QPointF(pt1.x() + x / len, pt1.y() + y / len));
635 if (qAbs(f.length() - 1) >= 0.001)
636 qWarning(
"QLine::unitVector: New line does not have unit length");
653QLineF::IntersectionType QLineF::intersects(
const QLineF &l, QPointF *intersectionPoint)
const
656 const QPointF a = pt2 - pt1;
657 const QPointF b = l.pt1 - l.pt2;
658 const QPointF c = pt1 - l.pt1;
660 const qreal denominator = a.y() * b.x() - a.x() * b.y();
661 if (denominator == 0 || !qt_is_finite(denominator))
662 return NoIntersection;
664 const qreal reciprocal = 1 / denominator;
665 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;
666 if (intersectionPoint)
667 *intersectionPoint = pt1 + a * na;
669 if (na < 0 || na > 1)
670 return UnboundedIntersection;
672 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;
673 if (nb < 0 || nb > 1)
674 return UnboundedIntersection;
676 return BoundedIntersection;