求空间一点到另外一点(如原点)的距离

class Point{
 double x,y,z;
   Point(double _x, double _y, double _z){
  x=_x;
  y=_y;
  z=_z;
  }
  
  double getDistance(Point p){
   return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z);
   }
 }
 public class TestPoint{
  public static void main(String[] args){
   Point p=new Point(1.0,2.0,3.0);
   Point p1=new Point(0.0,0.0,0.0);
   System.out.println(p.getDistance(p1));
   }
  }

posted on 2013-03-05 21:53  zhangqiang618  阅读(270)  评论(0编辑  收藏  举报