//获取一个点到另外两个点所在直线的投影。 如果点在直线上,返回其本身
//下面公式适用于二维空间的点, Y轴的数值不考虑
public static Vector3 GetProjectToLine(Vector3 _Point, Vector3 L0Point, Vector3 L1Point)
{
//去掉Y轴
_Point.y = 0;
L0Point.y = 0;
L1Point.y = 0;
if (GetPointToLine(_Point, L0Point, L1Point) == 0) return _Point;//如果点在直线上,返回其本身
Vector3 _pos = Vector3.zero;
float a0 = _Point.x;
float b0 = _Point.z;
float a1 = L0Point.x;
float b1 = L0Point.z;
float a2 = L1Point.x;
float b2 = L1Point.z;
float a1a2 = L0Point.x - L1Point.x;
float b1b2 = L0Point.z - L1Point.z;
_pos.x = (a0 * a1a2 * a1a2 + b0 * b1b2 * a1a2 - (b2 * a1 - b1 * a2) * b1b2) / (b1b2 * b1b2 + a1a2 * a1a2);
_pos.z = (b0 * b1b2 * b1b2 + a0 * b1b2 * a1a2 + (b2 * a1 - b1 * a2) * a1a2) / (b1b2 * b1b2 + a1a2 * a1a2);
return _pos;
}