点到直线的距离
//点到直线的距离public static double getDistanceByPointToLine采用笛卡尔坐标(Coordinate point, Coordinate pnt1, Coordinate pnt2)
{
double dis = 0;
if (pnt1.x == pnt2.x)
{
if (pnt1.y == pnt2.y)
{
double dx = point.x - pnt1.x;
double dy = point.y - pnt1.y;
dis = Math.sqrt(dx * dx + dy * dy);
}
else
dis = Math.abs(point.x - pnt1.x);
}
else
{
double lineK = (pnt2.y - pnt1.y) / (pnt2.x - pnt1.x);
double lineC = (pnt2.x * pnt1.y - pnt1.x * pnt2.y) / (pnt2.x - pnt1.x);
dis = Math.abs(lineK * point.x - point.y + lineC) / (Math.sqrt(lineK * lineK + 1));
}
//
return dis;
}
页:
[1]