简体   繁体   English

检查Point是否位于(或靠近)凸多边形边缘

[英]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. 因此,我正在将KML文件加载到我的Google地图上,它们在地图上显示为凸多边形。
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 :) 并且由于位置服务的准确性不是100%,因此如果位置很近(边缘距离15m),那就太好了:)

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. 我的解决方案是找到在2个顶点之间传递的函数y = f(x),然后检查用户位置是否低于f(x)+ a和高于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. 我感觉好像缺少了一些东西,应该有一种更好(更准确)的方法来解决我的问题,甚至应该有一个针对Android的Java库已经解决了这个问题。

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. 实际上,您可以为凸面多边形实现更好的时间复杂度,但是可能不值得实施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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