答案 0 :(得分:0)
数学:
正如wikipedia中所述 线和点之间的最短距离可以计算为 如下:
Java implimentaion
class Point {
double x,y;
Point(double pX, double pY){
this.x= pX;
this.y= pY;
}
public double distance(Point A1, Point A2){
double numerator = Math.abs((A2.y - A1.y)*this.x + (A2.x - A1.x)*this.y + A2.x*A1.y - A2.y*A1.x);
double denominator = Math.sqrt(Math.pow(A2.y - A1.y,2) + Math.pow(A2.x - A1.x,2));
return numerator/denominator;
}
}
要计算Point B
与Points A1
和A2
定义的行之间的距离,请使用distance
方法,如下所示:
public static void main (String[] args) throws java.lang.Exception
{
Point A1 = new Point(0,3);
Point A2 = new Point(2,0);
Point B = new Point(0,0);
System.out.println(
B.distance(A1,A2)
);
}
但请求基础知识,选择一些好的和有趣的编码书或啧啧,并给它一个去,快乐编码:)