在三维坐标系中求两个坐标点的距离(C++)

class Point{ 
public:
 Point(double x=0.0,double y=0.0,double z=0.0);
 void disp();
 friend class ComputeTools;
private:
 double x,y,z;
};
Point::Point(double x,double y,double z)
{ 
 this->x=x;
 this->y=y;
 this->z=z;
}
void Point::disp()
{ 
 cout<<"point:("<<x<<","<<y<<","<<z<<") ";
}

class ComputeTools{ 
 public:
  static double distance(Point p1,Point p2);


};
double ComputeTools::distance(Point p1,Point p2)
{ 
 return sqrt((p1.x-p2.x)*(p1.x-p2.x)
 +(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}

int main()
{ 
    Point p1(1.0,1.0,1.0),p2(0.0,0.0,0.0);
    p1.disp();
    p2.disp();
    cout<<" Distance: "<<ComputeTools::distance(p1,p2)<<endl;
    return 0;
}
    原文作者:烤鲅鱼
    原文地址: https://blog.csdn.net/qq_34674558/article/details/123023670
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞