zoukankan      html  css  js  c++  java
  • 计算三维空间的点与原点距离

     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 }
  • 相关阅读:
    Google glass GDK
    Google glass GDK
    Google glass GDK
    趣味开发
    Android
    Google glass GDK
    Google glass GDK
    Google glass GDK
    Android
    Google glass GDK
  • 原文地址:https://www.cnblogs.com/delphione/p/2985016.html
Copyright © 2011-2022 走看看