public class Line : IComparable<Line>
{
#region Members
private PointF start;
private PointF end;
#endregion
#region Constructors
public Line(PointF start, PointF end)
{
this.start = start;
this.end = end;
}
#endregion
#region Properties
public PointF Start
{
get
{
return start;
}
set
{
start = value;
}
}
public PointF End
{
get
{
return end;
}
set
{
end = value;
}
}
public double Angle
{
get
{
double dX = End.X - Start.X;
double dY = End.Y - Start.Y;
double angle = Math.Atan(dY / dX) * 180 / Math.PI;
if (dX < 0)
{
angle += 180;
}
if (angle < 0)
{
angle += 360;
}
return angle;
}
}
#endregion
#region Functions
public double IncludedAngleWith(Line line)
{
double angle = line.Angle;
if (angle < this.Angle)
{
angle += 360;
}
return angle - this.Angle;
}
public int CompareTo(Line line)
{
if (this.Angle < line.Angle)
{
return -1;
}
else if (this.Angle == line.Angle)
{
return 0;
}
else
{
return 1;
}
}
#endregion
}
public bool Contains(PointF[] vertexArray, PointF point)
{
Line[] lineArray = new Line[vertexArray.Length];
for (int index = 0; index < vertexArray.Length; index++)
{
if (vertexArray[index] == point) //判断点与顶点重合
{
return false;
}
lineArray[index] = new Line(point, vertexArray[index]);
}
Array.Sort(lineArray);
for (int index = 0; index < lineArray.Length - 1; index++)
{
if (lineArray[index].IncludedAngleWith(lineArray[index + 1]) >= 180)
{
return false;
}
}
if (lineArray[lineArray.Length - 1].IncludedAngleWith(lineArray[0]) >= 180)
{
return false;
}
return true;
}