计算两直线L1,L2交点函数IntersectLineLine()
// 计算两直线L1,L2交点函数IntersectLineLine()
//get the intersection point of line L1,L2
//returns:
//0: parallel 平行
//1: unique intersection via inter 相交 交点inter
//2: same line 同一条线
int CGMap2DTo3DDlg::IntersectLineLine(POINT2D L11, POINT2D L12, POINT2D L21, POINT2D L22, POINT2D& inter)
{
//L1: a1x+b1y=c1
double a1=L12.Y-L11.Y;
double b1=L11.X-L12.X;
double c1=L11.X*L12.Y-L12.X*L11.Y;
//L2: a2x+b2y=c2
double a2=L22.Y-L21.Y;
double b2=L21.X-L22.X;
double c2=L21.X*L22.Y-L22.X*L21.Y;
double detab=a1*b2-a2*b1;
if(detab==0)
{
double r;
if(a2!=0) r=a1/a2;
else r=b1/b2;
if(c1==0&&c2==0) return 2;
if(r==c1/c2) return 2;
else return 0;
}
inter.X=(c1*b2-c2*b1)/detab;
inter.Y=(a1*c2-a2*c1)/detab;
return 1;
}