GraphicsUtils.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace FWindSoft.Graphics
  7. {
  8. public class GraphicsUtils
  9. {
  10. public static bool InRegion(List<XYZ> vertexes, XYZ checkPoint)
  11. {
  12. //射线法,想x轴正方向做射线
  13. bool flag = false;
  14. int interectCount = 0;
  15. //判断是否在整个区域的范围内,如果在的话在进行下面的判断,不在的话直接返回
  16. double baseRef = checkPoint.Y;
  17. for (int i = 0; i < vertexes.Count; i++)
  18. {
  19. var first = vertexes[i];
  20. var second = vertexes[i % vertexes.Count];
  21. if ((first.Y < baseRef && second.Y < baseRef) && (first.Y > baseRef && second.Y > baseRef))
  22. {
  23. //肯定与射线没有交点
  24. continue;
  25. }
  26. #region 边界检测
  27. //判断点是否在线线上
  28. if (InLine(first, second, checkPoint))
  29. {
  30. flag = true;
  31. break;
  32. }
  33. #endregion
  34. /*一个相交点算一次,如果两条线重合,则单独计数一次,不在相交点去集合里
  35. */
  36. #region 交点个数检测
  37. //判断y等于0的点,X是否大于被检查点的X,如果大于记成一个交点
  38. if ((first.Y == baseRef && second.Y != baseRef))
  39. {
  40. if (checkPoint.X < first.X)
  41. {
  42. interectCount += 1;
  43. }
  44. }
  45. else if ((first.Y != baseRef && second.Y == baseRef))
  46. {
  47. if (checkPoint.X < second.X)
  48. {
  49. interectCount += 1;
  50. }
  51. }
  52. else if (first.Y == baseRef && second.Y == baseRef)
  53. {
  54. //如果线重合则记做两个点
  55. if (checkPoint.X < Math.Max(first.X, second.X))
  56. {
  57. interectCount += 2;
  58. }
  59. }
  60. else
  61. {
  62. //first和second异号,满足条件则记做1个点
  63. }
  64. #endregion
  65. }
  66. if (flag)
  67. {
  68. return true;
  69. }
  70. else
  71. {
  72. flag = interectCount % 2 == 1;
  73. }
  74. return flag;
  75. }
  76. public static bool CreateBoundBox(List<XYZ> vertexes)
  77. {
  78. bool flag = false;
  79. return flag;
  80. }
  81. /// <summary>
  82. /// 判断点是否在线上
  83. /// </summary>
  84. /// <param name="first">线的第一个点</param>
  85. /// <param name="second">线的第二个点</param>
  86. /// <param name="checkPoint"></param>
  87. /// <returns></returns>
  88. public static bool InLine(XYZ first,XYZ second,XYZ checkPoint)
  89. {
  90. bool flag = false;
  91. return flag;
  92. }
  93. }
  94. }