搜索
bottom↓
回复: 17

怎样判断GPS坐标在电子围栏内

[复制链接]

出0入57汤圆

发表于 2024-3-20 16:12:45 | 显示全部楼层
To determine whether a GPS coordinate is within an electronic fence, which is a convex polygon formed by multiple GPS coordinates, we can use the Ray Casting algorithm. The main idea is to draw a line segment from the coordinate to a point outside the polygon, and count how many edges it intersects. If the number of intersections is even, the coordinate is outside the polygon, otherwise it's inside.

This algorithm can accurately judge whether the coordinate is within the convex polygon. However, since the Earth is not a flat plane, if the GPS data in the vertices of the polygon crosses the change line (the boundary between 360 degrees and -360 degrees), it may cause problems, and may need to add or subtract in some corner data.

So, the implementation process is to traverse each edge of the polygon in turn, and determine whether the connection point of the coordinate and the edge is on the left or right of the edge vector. If it's on the right, it's considered to be intersected, otherwise it's not. When the last edge is judged, if the result is intersect, it means that the coordinate is outside the polygon, otherwise it's inside.

In conclusion, through the above algorithm, we can determine whether a GPS coordinate is within a given convex polygon (electronic fence).

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入57汤圆

发表于 2024-3-20 16:18:37 | 显示全部楼层
竟然有这么神奇的算法,从这个点随便往一个方向画一条线,数这条线和围栏的变交点的个数,奇数个就是在围栏里面,偶数个就是在围栏外面。

出0入57汤圆

发表于 2024-3-20 16:37:08 | 显示全部楼层
amazing030 发表于 2024-3-20 16:20
很不错的办法,那问题又来了,怎么判断相交点?
(引用自4楼)

要计算的点(x,y),假如竖着向下画线,边的两个点的x坐标一个比x大一个比x小就会相交,由于是往下画线,所以还需要再比较一下边的Y是不是有在点y下方的部分。估计搜索一下就能找到关于电子围栏的高效的并且成熟的计算方法。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-6-5 02:51

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表