给定平面上两条线段LineA与LineB,以及对应的端点坐标,计算出两条线段的交点
LineA (LineA_Pt1, LineA_Pt2) LineB(LineB_Pt1, LineB_Pt2)
// 仅适用于2D PointXY
templete<Point>
Point GetInterSectionPt(const Point &LineA_Pt1, const Point &LineA_Pt2,
const Point &LineB_Pt1, const Point &LineB_Pt2)
{
Point LineA_dir = LineA_Pt2 - LineA_Pt1;
LineA_dir.Normalize();
Point dir1 = LineB_Pt1 - LineA_Pt1;
Point dir2 = LineB_Pt2 - LineA_Pt1;
Double dProj1 = sqrt(pow(dir1.GetLength(), 2) - pow(dir1*LineA_dir, 2));
Double dProj2 = sqrt(pow(dir2.GetLength(), 2) - pow(dir2*LineA_dir, 2));
Point InterSection = (LineB_Pt1 * dProj2 + LineB_Pt2 * dProj1) / (dProj1 + dProj2);
return InterSection;
}