3 차원 공간의 점 과 원점 거 리 를 계산 하 다.

4236 단어
원본 링크:http://www.cnblogs.com/delphione/archive/2013/03/27/2985016.html
 1 //     point            (     ),    
 2 //1.            
 3 //2.             
 4 //3.                  
 5 
 6 class Point
 7 {
 8     double x,y,z;
 9     public Point(double _x,double _y,double _z)
10     {
11         x=_x;
12         y=_y;
13         z=_z;
14     }
15     public void setPoint(double _x)
16     {
17         x=_x;
18     }
19     public double getDistance(Point p)
20     {
21         return (x-p.x)*(x-p.x)+(y-p.x)*(y-p.x)+(z-p.x)*(z-p.x);
22     }
23 }
24 
25 public class TestPoint {
26     public static void main(String[] args) 
27     {
28         Point p=new Point(1.0,2.0,3.0);
29         Point p1=new Point(0.0,0.0,0.0);
30         System.out.println(p.getDistance(p1));
31         System.out.println(p.getDistance(new Point(1.0,1.0,1.0)));
32         
33         
34     }
35 
36 }

 
다음으로 전송:https://www.cnblogs.com/delphione/archive/2013/03/27/2985016.html

좋은 웹페이지 즐겨찾기