Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Easiest way to find the distance between two parallel QLineF?

    General and Desktop
    2
    2
    789
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jh224 last edited by

      Before delving deeper and looking at creating perpendicular lines and walking them, is there an easy solution for finding the parallel distance between 2 QLineFs?

      1 Reply Last reply Reply Quote 0
      • C
        chrisberlin last edited by

        From the math point of view, I guess the following should work (I'm tempted to say it's impossible to do it "simpler", but implementing the same operations using your own specialized code might be more performant):
        @QLineF normal = line1,normal();.
        QPointF crossPoint;
        if (normal.intersect(line2, &crossPoint) != QLineF::NoIntersection) {
        QLineF distanceLine(line1.p1(), crossPoint);
        qreal distance = distanceLine.length();
        }@
        Please note there is no check for actual parallelity; you can add it be comparison of the inclinations:
        @if (line1.dy() * line2.dx() == line1.dx() * line2.dy()) {
        // parallel
        } else {
        // not parallel
        }@

        1 Reply Last reply Reply Quote 0
        • First post
          Last post