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. QLineF::intersectType
Forum Updated to NodeBB v4.3 + New Features

QLineF::intersectType

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 702 Views 2 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.
  • C Offline
    C Offline
    Corny
    wrote on last edited by
    #1

    I have a QGraphicsScene with a QGraphicsObject that is animated and is traveling in a specific direction. Since I want it to remain within the scene, I’m attempting to continuously check the distance to each of the borders to determine which border the path intersects and where the path will intersect it. The intention of course, is to change the direction of travel prior to intersecting the border. To accomplish this, the current path is used to define a QLineF using the current position as p1, and a point several pixels along the path of travel as p2. Then the intersect function of that line is used to check for an UnboundedIntersection with each of the four borders.

    The documentation seems to imply that the direction of the line, or which end is point 1 or point 2, is irrelevant. I take that to mean that no matter the location of the line, or which direction the line is pointing, if I check for an unbounded intersection against every border, it will always return a BoundedIntersection or an UnboundedIntersection intersect type on all four borders unless the line is parallel with the border I’m checking it against.

    This diagram illustrates my point.
    QLineFImg.png
    Assuming that my interpretation of the documentation is correct, it there something that I have missed? Is there a way to check for an intersection between two lines only in the direction they are created, from p1 to p2?

    kshegunovK 1 Reply Last reply
    0
    • C Corny

      I have a QGraphicsScene with a QGraphicsObject that is animated and is traveling in a specific direction. Since I want it to remain within the scene, I’m attempting to continuously check the distance to each of the borders to determine which border the path intersects and where the path will intersect it. The intention of course, is to change the direction of travel prior to intersecting the border. To accomplish this, the current path is used to define a QLineF using the current position as p1, and a point several pixels along the path of travel as p2. Then the intersect function of that line is used to check for an UnboundedIntersection with each of the four borders.

      The documentation seems to imply that the direction of the line, or which end is point 1 or point 2, is irrelevant. I take that to mean that no matter the location of the line, or which direction the line is pointing, if I check for an unbounded intersection against every border, it will always return a BoundedIntersection or an UnboundedIntersection intersect type on all four borders unless the line is parallel with the border I’m checking it against.

      This diagram illustrates my point.
      QLineFImg.png
      Assuming that my interpretation of the documentation is correct, it there something that I have missed? Is there a way to check for an intersection between two lines only in the direction they are created, from p1 to p2?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #3

      That can be easily checked when solving the system to determine the intersection. Here's a fully functional code [1] you can adapt to your case, but yes, you need to do it on your side.

      [1]: https://codereview.qt-project.org/c/qt/qtbase/+/261770/1/src/corelib/tools/qline.cpp

      Read and abide by the Qt Code of Conduct

      C 1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Corny said in QLineF::intersectType:

        Is there a way to check for an intersection between two lines only in the direction they are created, from p1 to p2?

        Yes, but you have to write it on your own. But since you get the interesectionPoint from QLineF::intersect() it shouldn't be too hard to determine the direction of the line to this point by yourself.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply
        2
        • C Corny

          I have a QGraphicsScene with a QGraphicsObject that is animated and is traveling in a specific direction. Since I want it to remain within the scene, I’m attempting to continuously check the distance to each of the borders to determine which border the path intersects and where the path will intersect it. The intention of course, is to change the direction of travel prior to intersecting the border. To accomplish this, the current path is used to define a QLineF using the current position as p1, and a point several pixels along the path of travel as p2. Then the intersect function of that line is used to check for an UnboundedIntersection with each of the four borders.

          The documentation seems to imply that the direction of the line, or which end is point 1 or point 2, is irrelevant. I take that to mean that no matter the location of the line, or which direction the line is pointing, if I check for an unbounded intersection against every border, it will always return a BoundedIntersection or an UnboundedIntersection intersect type on all four borders unless the line is parallel with the border I’m checking it against.

          This diagram illustrates my point.
          QLineFImg.png
          Assuming that my interpretation of the documentation is correct, it there something that I have missed? Is there a way to check for an intersection between two lines only in the direction they are created, from p1 to p2?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #3

          That can be easily checked when solving the system to determine the intersection. Here's a fully functional code [1] you can adapt to your case, but yes, you need to do it on your side.

          [1]: https://codereview.qt-project.org/c/qt/qtbase/+/261770/1/src/corelib/tools/qline.cpp

          Read and abide by the Qt Code of Conduct

          C 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @Corny said in QLineF::intersectType:

            Is there a way to check for an intersection between two lines only in the direction they are created, from p1 to p2?

            Yes, but you have to write it on your own. But since you get the interesectionPoint from QLineF::intersect() it shouldn't be too hard to determine the direction of the line to this point by yourself.

            C Offline
            C Offline
            Corny
            wrote on last edited by
            #4

            @Christian-Ehrlicher
            I believe I'll still get two unbounded intersections. But your right, it can be figured out from there. However, at this point though, the only solution I can come up with seems clumsy and unwieldy. I was kind of hopping someone might have a more elegant solution than the one I've awkwardly flung together.
            Thank you for your reply.

            1 Reply Last reply
            0
            • kshegunovK kshegunov

              That can be easily checked when solving the system to determine the intersection. Here's a fully functional code [1] you can adapt to your case, but yes, you need to do it on your side.

              [1]: https://codereview.qt-project.org/c/qt/qtbase/+/261770/1/src/corelib/tools/qline.cpp

              C Offline
              C Offline
              Corny
              wrote on last edited by
              #5

              @kshegunov
              Thanks for your response. I'll be going through the code you provided.

              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