Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Easiest way to find the distance between two parallel QLineF?

Easiest way to find the distance between two parallel QLineF?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • 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 Offline
    J Offline
    jh224
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      chrisberlin
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved