简体   繁体   中英

Check if Point is located on(or close to) a convex polygon edges

So I'm loading KML files to my google map, they are shown as convex polygons on the map.
I also have the user location , basically i want to know if the user is located on one of the polygon's edges (which is a convex polygon).
and because location services aren't 100% accurate, if the location is close (the edge is 15m far)- that's good :)

My solution is to find the function y=f(x) that passes between 2 vertices, then check if the user location is below f(x)+a and above f(x)-a.

I feel like I'm missing something and there should be a better (and more accurate) way to solve my issue or even maybe a java library for android that already tackle this.

Thanks :)

您可以使用PolyUtil.isLocationOnEdge()正是您想要的。

You should implement a function that determines the distance from a point to a line segment. You can find code all over the web for this, eg, here: " Shortest distance between a point and a line segment ." Then iterate over each segment of the polygon. This works even if the polygon is nonconvex.

You can actually achieve better time complexity for convex polygons, but likely that would not be worth the implementation effort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM