當前位置:編程學習大全網 - 編程軟體 - 構造壹空間球類,並能處理判別空間任意兩球體幾何關系。c++編程題,跪

構造壹空間球類,並能處理判別空間任意兩球體幾何關系。c++編程題,跪

# include<iostream>

# include<cmath>

using namespace std;

class ball//定義空間球類

{

protecteed:

double x,y,z;//球心坐標

double r;//球半徑

public:

ball(double x,double y,double z,double r)//構造函數

{

this->x=x;

this->y=y;

this->z=z;

this->r=r;

}

double GetRadius()//返回球的半徑

{

return r;

}

double GetX()//返回x坐標

{

retrun x;

}

double GetY()//返回y坐標

{

retrun y;

}

double GetZ()//返回z坐標

{

retrun z;

}

};

void Relation(ball&a,ball&b)//比較球a,b關系

{

double distance=sqrt(pow(a.GetX()-b.GetX(),2),pow(a.GetY()-b.GetY(),2)pow(a.GetZ()-b.GetZ(),2));

double R=a.GetRadius()+b.GetRadius();

if(distance==R)

cout<<"相切"<<endl;

else if(distance>R)

cout<<"相離"<<endl;

else

cout<<"相交"<<endl;

}

int main()

{

ball a(0,0,0,1);

ball b(1,1,1,1);

a.Relation(a,b);

return 0;

}

  • 上一篇:怎麽在eclipse上面開發安卓編程
  • 下一篇:易語言讓這壹段命令循環 另外 怎麽用時鐘?寫壹個時鐘60秒後關機
  • copyright 2024編程學習大全網