123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Graphics
- {
- public class GraphicsUtils
- {
- public static bool InRegion(List<XYZ> vertexes, XYZ checkPoint)
- {
- //射线法,想x轴正方向做射线
- bool flag = false;
- int interectCount = 0;
- //判断是否在整个区域的范围内,如果在的话在进行下面的判断,不在的话直接返回
- double baseRef = checkPoint.Y;
- for (int i = 0; i < vertexes.Count; i++)
- {
- var first = vertexes[i];
- var second = vertexes[i % vertexes.Count];
- if ((first.Y < baseRef && second.Y < baseRef) && (first.Y > baseRef && second.Y > baseRef))
- {
- //肯定与射线没有交点
- continue;
- }
- #region 边界检测
- //判断点是否在线线上
- if (InLine(first, second, checkPoint))
- {
- flag = true;
- break;
- }
- #endregion
- /*一个相交点算一次,如果两条线重合,则单独计数一次,不在相交点去集合里
- */
- #region 交点个数检测
- //判断y等于0的点,X是否大于被检查点的X,如果大于记成一个交点
- if ((first.Y == baseRef && second.Y != baseRef))
- {
- if (checkPoint.X < first.X)
- {
- interectCount += 1;
- }
- }
- else if ((first.Y != baseRef && second.Y == baseRef))
- {
- if (checkPoint.X < second.X)
- {
- interectCount += 1;
- }
- }
- else if (first.Y == baseRef && second.Y == baseRef)
- {
- //如果线重合则记做两个点
- if (checkPoint.X < Math.Max(first.X, second.X))
- {
- interectCount += 2;
- }
- }
- else
- {
- //first和second异号,满足条件则记做1个点
-
- }
- #endregion
- }
- if (flag)
- {
- return true;
- }
- else
- {
- flag = interectCount % 2 == 1;
- }
- return flag;
- }
- public static bool CreateBoundBox(List<XYZ> vertexes)
- {
- bool flag = false;
- return flag;
- }
- /// <summary>
- /// 判断点是否在线上
- /// </summary>
- /// <param name="first">线的第一个点</param>
- /// <param name="second">线的第二个点</param>
- /// <param name="checkPoint"></param>
- /// <returns></returns>
- public static bool InLine(XYZ first,XYZ second,XYZ checkPoint)
- {
- bool flag = false;
-
- return flag;
- }
- }
- }
|