Results 1 to 2 of 2

Thread: Understanding QLineF::intersectType

  1. #1
    Join Date
    Nov 2016
    Ridgecrest California
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Windows Android

    Default Understanding QLineF::intersectType

    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 unless the line is parallel with the border I’m checking it against. I had a diagram illustrating my point but couldn't upload it. So this is the code I'm attempting to use for checking for a border...

    Qt Code:
    1. QPointF Target::checkEdge(QPointF crntPos)
    2. {
    3. QPointF intrsctPoint; // New point for intersection
    5. const QLineF nEdge(0, 0, 1000, 0); // Initialize N edge boundry
    6. const QLineF sEdge(0, 1000, 1000, 1000); // Initialize S edge boundry
    7. const QLineF eEdge(1000, 0, 1000, 1000); // Initialize E edge boundry
    8. const QLineF wEdge(0, 0, 0, 1000); // Initialize W edge boundry
    10. QLineF track = QLineF::fromPolar(1, heading); // Track w/angle
    11. track.translate(crntPos); // Start line at current pos
    12. if(track.intersect(eEdge, &intrsctPoint) == QLineF::UnboundedIntersection)
    13. track.setP2(intrsctPoint);
    14. if(track.intersect(nEdge, &intrsctPoint) == QLineF::UnboundedIntersection)
    15. track.setP2(intrsctPoint);
    16. if(track.intersect(wEdge, &intrsctPoint) == QLineF::UnboundedIntersection)
    17. track.setP2(intrsctPoint);
    18. if(track.intersect(sEdge, &intrsctPoint) == QLineF::UnboundedIntersection)
    19. track.setP2(intrsctPoint);
    21. return intrsctPoint;
    22. }
    To copy to clipboard, switch view to plain text mode 

    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?

    Thank you in advance for your response

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 753 Times in 743 Posts
    Qt products
    Windows Android

    Default Re: Understanding QLineF::intersectType

    This seems like an overly complicated solution. Can't you simply use the boundingRect or sceneBoundingRect of your graphics object and look for the proximity of each edge to the scene bounds?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Adjusting QLineF points AFTER it has been drawn
    By bauervision in forum Qt Programming
    Replies: 0
    Last Post: 8th March 2017, 14:46
  2. QGraphicsItem, QLineF Precise Selection
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2009, 11:01
  3. What's the difference? (QLineF, pos, setPoints())
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 28th October 2009, 11:52
  4. problem in QLinef()
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 27th February 2009, 09:44
  5. Looking for ideas for QLineF objects
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 29th February 2008, 11:46

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.