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
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.