566qreal QLineF::angle()
const
568 const qreal dx = pt2.x() - pt1.x();
569 const qreal dy = pt2.y() - pt1.y();
571 const qreal theta = qRadiansToDegrees(qAtan2(-dy, dx));
573 const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
575 if (qFuzzyCompare(theta_normalized, qreal(360)))
578 return theta_normalized;
615QLineF QLineF::fromPolar(qreal length, qreal angle)
617 const qreal angleR = qDegreesToRadians(angle);
618 return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
628QLineF QLineF::unitVector()
const
630 const qreal x = dx();
631 const qreal y = dy();
633 const qreal len = qHypot(x, y);
634 QLineF f(p1(), QPointF(pt1.x() + x / len, pt1.y() + y / len));
637 if (qAbs(f.length() - 1) >= 0.001)
638 qWarning(
"QLine::unitVector: New line does not have unit length");
655QLineF::IntersectionType QLineF::intersects(
const QLineF &l, QPointF *intersectionPoint)
const
658 const QPointF a = pt2 - pt1;
659 const QPointF b = l.pt1 - l.pt2;
660 const QPointF c = pt1 - l.pt1;
662 const qreal denominator = a.y() * b.x() - a.x() * b.y();
663 if (denominator == 0 || !qt_is_finite(denominator))
664 return NoIntersection;
666 const qreal reciprocal = 1 / denominator;
667 const qreal na = (b.y() * c.x() - b.x() * c.y()) * reciprocal;
668 if (intersectionPoint)
669 *intersectionPoint = pt1 + a * na;
671 if (na < 0 || na > 1)
672 return UnboundedIntersection;
674 const qreal nb = (a.x() * c.y() - a.y() * c.x()) * reciprocal;
675 if (nb < 0 || nb > 1)
676 return UnboundedIntersection;
678 return BoundedIntersection;