Results 1 to 2 of 2

Thread: How to find the nearest point on a QPainterPath

  1. #1
    Join Date
    Feb 2010
    Location
    Los Angeles
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to find the nearest point on a QPainterPath

    Hello all,

    I need to find a point on a QPainterPath that is nearest to an arbitrary point outside the QPainterPath.
    For example: I have a QPainterPath that is a circle and a point outside the circle. Now I want to draw the shortest possible line between the circle and the point.

    If I use connectPath() it always connects to the beginning of the path (circle) which is never the nearest point.

    How can I do that?


    Markus

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to find the nearest point on a QPainterPath

    There are mathematical techniques for determing such points, but they require access to the mathematical definition of the curve involved. Qt doesn't make this information available, and doesn't provide such a function as part of QPainterPath.

    If the paths involved are always simple (circles, for instance, or straight line segments) you should be able to come up with a solution independently. If the curve is arbitrary, however, you are probably out of luck short of a brute-force approach of some sort.

  3. The following user says thank you to SixDegrees for this useful post:

    Markus (14th June 2010)

Similar Threads

  1. Replies: 1
    Last Post: 3rd December 2009, 14:23
  2. How to find the intersection point of polylines
    By arashadsaifi in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2009, 10:12
  3. QTreeView: Find nearest item to mouse pointer
    By squidge in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2009, 20:24
  4. how to paint scene point by point
    By elessaar in forum Qt Programming
    Replies: 8
    Last Post: 4th September 2008, 20:00
  5. Find point of intersection/overlaping?
    By Morea in forum Qt Programming
    Replies: 9
    Last Post: 19th April 2007, 14:42

Tags for this Thread

Bookmarks

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.