1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <cmath>
using namespace std;
class chgcoord
{
public:
struct carthe
{
double x,y,z;
carthe(double xx=0,double yy=0,double zz=0):x(xx),y(yy),z(zz){}
};
struct pol {double r,t,f;pol(double rr,double tt,double ff):r(rr),t(tt),f(ff){} };
static void changement_de_coordonnees(chgcoord::carthe& c,const chgcoord::pol& p )
{
c.x=p.r*cos(p.t)*sin(p.f);
c.y=p.r*sin(p.f)*sin(p.t);
c.z=p.r*cos(p.f);
}
};
int main()
{
chgcoord::pol p(20,45,45);
chgcoord::carthe result;
chgcoord::changement_de_coordonnees(result, p);
cout<< " x = " << result.x << endl << "y = " << result.y << endl << "z=" << result.z << endl;
} |
Partager