我需要在C#中实现地理栅栏。 Geofence区域可以是圆形,矩形,多边形等。有没有人在C#中使用Geofence实现?我发现Geo Fencing - point inside/outside polygon。但是,它只支持多边形。实现地理栅栏 - C#
3
A
回答
1
6
我已经测试了各种实现方式和这个例子正常工作对我来说:
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;
}
+1
伟大的答案Fnascimento! – 2014-08-01 13:47:24
相关问题
- 1. 地理栅栏理解地理栅栏一生
- 2. Android更新地理栅栏
- 3. 谷歌播放地理栅栏onHandleIntent
- 4. Java中的地理栅栏库
- 5. woocommerce中的地理栅栏产品
- 6. Google地理栅栏 - 绘制矩形
- 7. 如何创建地理栅栏
- 8. Android地理栅栏广播接收器
- 9. 一致的Android地理栅栏监测
- 10. Android中路由的地理栅栏
- 11. 地理栅栏不能删除?
- 12. 使用Google玻璃的地理栅栏
- 13. 触发后删除地理栅栏
- 14. 地理栅栏API工作灯
- 15. 在Google地图中处理多个地理栅栏
- 16. 地理栅栏:如何识别使用Oracle Spatial重叠地理栅栏边界的对象(要素)?
- 17. Android中的地理栅栏和离线地图
- 18. 动态地理栅栏和谷歌地图Android应用程序
- 19. 在google地图中获取城市的地理栅栏
- 20. 用于圆形和矩形地理栅栏的C逻辑/算法?
- 21. 获取所有注册地理栅栏的列表
- 22. Android - 如何检索已注册地理栅栏的列表
- 23. Siddhi查询地理栅栏入口检测
- 24. Android的地理栅栏不会得到任何过渡upates
- 25. 针对xamarin ios的多个区域的地理栅栏
- 26. 在不同的用户上创建地理栅栏
- 27. 在android中添加地理栅栏服务
- 28. 地理栅栏背景应用程序可能吗?
- 29. 创建用户定义地理栅栏的算法
- 30. Android的地理栅栏上没有错误,但
多边形trivially包含矩形作为一种特殊情况(假设您设法定义球体上的矩形实际上是什么)。圆圈可以用毕达哥拉斯定理来检查。 – CodesInChaos 2011-03-18 13:26:53