Http://www.bkjia.com/kf/201111/112304.html tonight
The c # code is written to determine whether the two line segments overlap. The basic idea is the intersection of two line segments. For any line segment, the points at both ends are on both sides of the other line.
/// <Summary>
/// Determine whether two points of Line 2 are on either side of Line 1.
/// </Summary>
/// <Param name = "line1"> line 1 </param>
/// <Param name = "line2"> line 2 </param>
/// <Returns> </returns>
Private bool CheckCrose (Line line1, Line line2)
{
PointF v1 = new PointF ();
PointF v2 = new PointF ();
PointF v3 = new PointF ();
V1.X = line2.Start. X-line1.End. X;
V1.Y = line2.Start. Y-line1.End. Y;
V2.X = line2.End. X-line1.End. X;
V2.Y = line2.End. Y-line1.End. Y;
V3.X = line1.Start. X-line1.End. X;
V3.Y = line1.Start. Y-line1.End. Y;
Return (CrossMul (v1, v3) * CrossMul (v2, v3) <= 0 );
}
/// <Summary>
/// Determine whether two line segments meet each other.
/// </Summary>
/// <Param name = "line1"> Line Segment 1 </param>
/// <Param name = "line2"> Line Segment 2 </param>
/// <Returns> returns true if the intersection is true. Otherwise, false is returned. </Returns>
Private bool CheckTwoLineCrose (Line line1, Line line2)
{
Return CheckCrose (line1, line2) & CheckCrose (line2, line1 );
}
/// <Summary>
/// Calculate the cross multiplication of two vectors.
/// </Summary>
/// <Param name = "pt1"> </param>
/// <Param name = "pt2"> </param>
/// <Returns> </returns>
Private float CrossMul (PointF pt1, PointF pt2)
{
Return pt1.X * pt2.Y-pt1.Y * pt2.X;
}
Author I _code