点导直线的距离
来源:百度知道 编辑:UC知道 时间:2024/04/26 17:12:55
// 已知三点的坐标:
float Ax,Bx,Cx,Ay,By,Cy;
求C 到AB直线的距离.
L = sqrt( (Bx-Ax)^2 + (By-Ay)^2 );
s = ((Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)) / (L * L);
距离:
distance= fabs(s) * L;
若A,B点重合,两点迭在一起,L=0, 距离:
distance= sqrt( (Cx-Ax)^2 + (Cy-Ay)^2 );
public class Distance
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please input the coordinates of the first point");
double aX = input.nextDouble();
double aY = input.nextDouble();
System.out.println("Please input the coordinates of the second point");
double bX = input.nextDouble();
double bY = input.nextDouble();
System.out.println("Please input the coordinates of the third point");
double cX = input.nextDouble();
double cY = input.nextDouble();
double ac = Math.sqrt((aY - cY) *