Cualquier duda no dudes en contactar.
//Converts from rectangular coordinates to latitude/longitude and vice
//versa. Uses degrees (not radians).
#include <bits/stdc++.h>
using namespace std;
struct ll { double r, lat, lon; };
struct rect { double x, y, z; };
ll convert(rect& P) {
ll Q;
Q.r = sqrt(P.x*P.x+P.y*P.y+P.z*P.z);
Q.lat = 180/M_PI*asin(P.z/Q.r);
Q.lon = 180/M_PI*acos(P.x/sqrt(P.x*P.x+P.y*P.y));
return Q; }
rect convert(ll& Q) {
rect P;
P.x = Q.r*cos(Q.lon*M_PI/180)*cos(Q.lat*M_PI/180);
P.y = Q.r*sin(Q.lon*M_PI/180)*cos(Q.lat*M_PI/180);
P.z = Q.r*sin(Q.lat*M_PI/180);
return P; }
int main() {
rect A; ll B;
A.x = -1.0; A.y = 2.0; A.z = -3.0;
B = convert(A);
cout << B.r << " " << B.lat << " " << B.lon << endl;
A = convert(B);
cout << A.x << " " << A.y << " " << A.z << endl;
}
Sigue en contacto con Isaac Lozano Osorio!