语言:c#
需求:已知直线上的两点,判断第三个点与该直线的位置关系。
/// 判断点和直线的位置关系
/// <param name="LineA">直线上的一点</param>
/// <param name="LineB">直线上的另一点</param>
/// <param name="PntM">需要判断的点</param>
/// <returns></returns>
private int JudgePointToLine(Point LineA, Point LineB, Point PntM)
{
int nResult = 0;
double ax = LineB.X - LineA.X;
double ay = LineB.Y - LineA.Y;
double bx = PntM.X - LineA.X;
double by = PntM.Y - LineA.Y;
double judge = ax * by - ay * bx;
if (judge > 0) {
nResult = 1;
}else if (judge < 0){
nResult = -1;
}else {
nResult = 0;
}
return nResult;
}