1. 程式人生 > >Qt中求兩線段交點

Qt中求兩線段交點

color pan map section inter pointf nbsp span turn

QPointF MapEditor::getIntersectPos(QPointF posA, QPointF posB, QPointF posC, QPointF posD)//返回AB與CD交點,無交點返回(0,0)
{
    QLineF line1(posA, posB);
    QLineF line2(posC, posD);
    QPointF interPos(0,0);
    QLineF::IntersectType type = line1.intersect(line2, &interPos);
    if (type != QLineF::BoundedIntersection)
        interPos 
= QPointF(0, 0); return interPos; }

Qt中求兩線段交點