class Point
{
double x, y, z;
Point(double _x, double _y, double _z)
{
x = _x;
y = _y;
z = _z;
}
double getDistance(Point p)
{
return Math.sqrt(Math.pow(this.x - p.x, 2) + Math.pow(this.y - p.y, 2) + Math.pow(this.z - p.z, 2));
}
}
public class Test
{
public static void main(String[] args)
{
Point p = new Point(1, 1, 1);
Point p1 = new Point(0.0, 0.0, 0.0);
System.out.println(p.getDistance(p1));
}
}
距离是用三维空间中的勾股定理计算的。
|