求助,希望大家帮助
我这有个程序,我希望当输入r,a,h时可以转换成x,y,z,而当输入x,y,z时转换成r,a,h,可是我只会单方向的转换,忘好心人帮助#include<iostream>//站心地平直角坐标系与站心地平极坐标系的转换
#include<cmath>
using namespace std;
int main()
{
float r ,a ,h;//r,a,h分别站心极坐标坐标系三个参数距离,方位角,高度角
float x,y,z;//x,y,z分别为站心直角坐标系三个参数
const double pi=3.141592653;
cout<<"请输入r:"<<endl;
cin>>r;
cout<<" 请输入a:"<<endl;
cin>>a;
cout<<"请输入h:"<<endl;
cin>>h;
x=r*cos(a*pi/180)*cos(h*pi/180);
y=r*cos(h*pi/180)*sin(a*pi/180);
z=r*sin(h*pi/180);
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
cout<<"z="<<z<<endl;
float i,j,k;//i,j,h为重新定义的站心极坐标系的三个参数,通过得到x,y,z重新换算出站心极坐标
i=sqrt(x*x+y*y+z*z);
j=atan(y/x)*180/pi;
k=atan(z/sqrt(x*x+y*y))*180/pi;
cout<<"i="<<i<<endl;
cout<<"j="<<j<<endl;
cout<<"k="<<k<<endl;
return 0;
}