[Interest] Distance from point to path.
Elvis Stansvik
elvstone at gmail.com
Wed Dec 30 15:03:33 CET 2015
2015-12-29 19:47 GMT+01:00 william.crocker at analog.com
<william.crocker at analog.com>:
>>>>>
>>>>> Given a QPoint and a QPainterPath.
>>>>> How do I find the distance from the QPoint to the
>>>>> closest point along the QPainterPath.
>>>>>
>>
>> Perhaps. But you should consider that QPainterPath is, as the name
>> suggests, primarily for painting, and not meant for solving generic
>> geometric problems. So I'm not sure how a feature request for this
>> would be received by the Qt devs. Point projection is one problem, but
>> there are many others, and they are surely not all within the scope of
>> QPainterPath.
>>
>
> I think Qt opened the door for geometric consideration when they
> invented the scene, gave items mouse-event-handlers and provided
> intersection based item queries. :-)
Fair enough :) You could always try filing a feature request and see
what people think.
>
>> If I were you, I would instead try to find a library that can
>> calculate the minimum point-to-bezier distance, or if you feel up for
>> it, implement it yourself. The line case is trivial.
>
>
> I do not take the addition of a new library and the subsequent
> dependency lightly.
>
> In this case, I will just brute force with pointAtPercent.
I don't know what your paths looks like, but if you feel you need to
improve on this just a little bit, without having to implement one of
the advanced algorithms based on root finding, you could always just
iterate the elements of the path, and in the case an element is a
bézier curve segment, use a simpler algorithm like the one described
in this answer:
http://stackoverflow.com/a/34520607/252857
And you can of course skip running the subdivision algorithm above on
curve segments where the end points/control points are all further
away than the current minimum, because of the convex hull property of
bézier curves.
This would give a little better performance and accuracy than just
using pointAtPercent, if your paths are complex.
Elvis
>
> Thanks.
>
> Bill
>
>
>>
>> Elvis
>>
>>>
>>> I could then use QGraphicsScene::items() to find the
>>> intersecting set of a bounding rectangle around the
>>> mouse click and then nail it down with distance to
>>> each object in that set.
>>>
>>>
>>>> Elvis
>>>>
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Bill
>>>>>
>>>>> ---------
>>>>> All of the above to find the shape closest to a mouse click.
>>>>> Note that methods are provided to find the set of objects
>>>>> which intersect a rectangle centered on the point, but which one
>>>>> is really the closest?
>>>>> _______________________________________________
>>>>> Interest mailing list
>>>>> Interest at qt-project.org
>>>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>>
>>>>
>>>>
>>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list