- 积分
- 1448
- 明经币
- 个
- 注册时间
- 2011-10-24
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- /// <summary>
- /// 判断点是否在多边形内
- /// </summary>
- /// <param name="checkPoint">需要判断的点</param>
- /// <param name="polygonPoints">组成多边形点的集合</param>
- /// <returns></returns>
- public static bool IsInPolygon2(Point3d checkPoint, Point3dCollection polygonPoints)
- {
- int counter = 0;
- int i;
- double xinters;
- Point3d p1, p2;
- int pointCount = polygonPoints.Count;
- p1 = polygonPoints[0];
- for (i = 1; i <= pointCount; i++)
- {
- p2 = polygonPoints[i % pointCount];
- if (checkPoint.Y > Math.Min(p1.Y, p2.Y)//校验点的Y大于线段端点的最小Y
- && checkPoint.Y <= Math.Max(p1.Y, p2.Y))//校验点的Y小于线段端点的最大Y
- {
- if (checkPoint.X <= Math.Max(p1.X, p2.X))//校验点的X小于等线段端点的最大X(使用校验点的左射线判断).
- {
- if (p1.Y != p2.Y)//线段不平行于X轴
- {
- xinters = (checkPoint.Y - p1.Y) * (p2.X - p1.X) / (p2.Y - p1.Y) + p1.X;
- if (p1.X == p2.X || checkPoint.X <= xinters)
- {
- counter++;
- }
- }
- }
- }
- p1 = p2;
- }
- if (counter % 2 == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
复制代码
|
|