1. public class Line : IComparable<Line>
    2. {
    3. #region Members
    4. private PointF start;
    5. private PointF end;
    6. #endregion
    7. #region Constructors
    8. public Line(PointF start, PointF end)
    9. {
    10. this.start = start;
    11. this.end = end;
    12. }
    13. #endregion
    14. #region Properties
    15. public PointF Start
    16. {
    17. get
    18. {
    19. return start;
    20. }
    21. set
    22. {
    23. start = value;
    24. }
    25. }
    26. public PointF End
    27. {
    28. get
    29. {
    30. return end;
    31. }
    32. set
    33. {
    34. end = value;
    35. }
    36. }
    37. public double Angle
    38. {
    39. get
    40. {
    41. double dX = End.X - Start.X;
    42. double dY = End.Y - Start.Y;
    43. double angle = Math.Atan(dY / dX) * 180 / Math.PI;
    44. if (dX < 0)
    45. {
    46. angle += 180;
    47. }
    48. if (angle < 0)
    49. {
    50. angle += 360;
    51. }
    52. return angle;
    53. }
    54. }
    55. #endregion
    56. #region Functions
    57. public double IncludedAngleWith(Line line)
    58. {
    59. double angle = line.Angle;
    60. if (angle < this.Angle)
    61. {
    62. angle += 360;
    63. }
    64. return angle - this.Angle;
    65. }
    66. public int CompareTo(Line line)
    67. {
    68. if (this.Angle < line.Angle)
    69. {
    70. return -1;
    71. }
    72. else if (this.Angle == line.Angle)
    73. {
    74. return 0;
    75. }
    76. else
    77. {
    78. return 1;
    79. }
    80. }
    81. #endregion
    82. }
    83. public bool Contains(PointF[] vertexArray, PointF point)
    84. {
    85. Line[] lineArray = new Line[vertexArray.Length];
    86. for (int index = 0; index < vertexArray.Length; index++)
    87. {
    88. if (vertexArray[index] == point) //判断点与顶点重合
    89. {
    90. return false;
    91. }
    92. lineArray[index] = new Line(point, vertexArray[index]);
    93. }
    94. Array.Sort(lineArray);
    95. for (int index = 0; index < lineArray.Length - 1; index++)
    96. {
    97. if (lineArray[index].IncludedAngleWith(lineArray[index + 1]) >= 180)
    98. {
    99. return false;
    100. }
    101. }
    102. if (lineArray[lineArray.Length - 1].IncludedAngleWith(lineArray[0]) >= 180)
    103. {
    104. return false;
    105. }
    106. return true;
    107. }