[Interest] Distance from point to path.

Elvis Stansvik elvstone at gmail.com
Tue Dec 29 12:42:23 CET 2015


2015-12-28 22:49 GMT+01:00 william.crocker at analog.com
<william.crocker at analog.com>:
> Hello:
>
> Given a QPoint and a QPainterPath.
> How do I find the distance from the QPoint to the
> closest point along the QPainterPath.
>
> I could step along the path with pointAtPercent
> looking for the closest point, but that seems unduly
> expensive: O(100N).
>
> Any better ideas.

Like Konstantin said, the best approach probably depends on whether
you know something about your paths or not (all lines? all arcs?
et.c.). But if you want something that works for general paths, then
you'll need a battery of algorithms, including one that works for
beziers. Here's one for beziers I found through some googling:

  https://hal.archives-ouvertes.fr/file/index/docid/518379/filename/Xiao-DiaoChen2007c.pdf

It does sound like a problem that has been solved many times though
(boost_geometry perhaps?), so depending on your license, maybe you
could find a geometry library you could use.

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



More information about the Interest mailing list