PS:从其他地方看到的源码是有问题的。下面是修正后的
///
/// 计算两条直线的交点
///
/// L1的点1坐标
/// L1的点2坐标
/// L2的点1坐标
/// L2的点2坐标
///
public static PointF GetIntersection(PointF lineFirstStar, PointF lineFirstEnd, PointF lineSecondStar, PointF lineSecondEnd)
{
/*
* L1,L2都存在斜率的情况:
* 直线方程L1: ( y - y1 ) / ( y2 - y1 ) = ( x - x1 ) / ( x2 - x1 )
* => y = [ ( y2 - y1 ) / ( x2 - x1 ) ]( x - x1 ) + y1
* 令 a = ( y2 - y1 ) / ( x2 - x1 )
* 有 y = a * x - a * x1 + y1 .........1
* 直线方程L2: ( y - y3 ) / ( y4 - y3 ) = ( x - x3 ) / ( x4 - x3 )
* 令 b = ( y4 - y3 ) / ( x4 - x3 )
* 有 y = b * x - b * x3 + y3 ..........2
*
* 如果 a = b,则两直线平等,否则, 联解方程 1,2,得:
* x = ( a * x1 - b * x3 - y1 + y3 ) / ( a - b )
* y = a * x - a * x1 + y1
*
* L1存在斜率, L2平行Y轴的情况:
* x = x3
* y = a * x3 - a * x1 + y1
*
* L1 平行Y轴,L2存在斜率的情况:
* x = x1
* y = b * x - b * x3 + y3
*
* L1与L2都平行Y轴