实施地理围栏 – C#
发布时间:2020-12-16 01:42:11 所属栏目:百科 来源:网络整理
导读:我需要在C#中实现Geofence.地理围栏区域可以是圆形,矩形,多边形等.有没有人在C#中实现Geofence? 我找到了Geo Fencing – point inside/outside polygon.但是,它只支持多边形. 解决方法 我测试了各种实现,这个例子适合我: Example public static bool PolyC
我需要在C#中实现Geofence.地理围栏区域可以是圆形,矩形,多边形等.有没有人在C#中实现Geofence?
我找到了Geo Fencing – point inside/outside polygon.但是,它只支持多边形. 解决方法
我测试了各种实现,这个例子适合我:
Example public static bool PolyContainsPoint(List<Point> points,Point p) { bool inside = false; // An imaginary closing segment is implied,// so begin testing with that. Point v1 = points[points.Count - 1]; foreach (Point v0 in points) { double d1 = (p.Y - v0.Y) * (v1.X - v0.X); double d2 = (p.X - v0.X) * (v1.Y - v0.Y); if (p.Y < v1.Y) { // V1 below ray if (v0.Y <= p.Y) { // V0 on or above ray // Perform intersection test if (d1 > d2) { inside = !inside; // Toggle state } } } else if (p.Y < v0.Y) { // V1 is on or above ray,V0 is below ray // Perform intersection test if (d1 < d2) { inside = !inside; // Toggle state } } v1 = v0; //Store previous endpoint as next startpoint } return inside; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |