How can i map both angles (theta and phi) of the spherical coordinates to 360 degrees

817 views Asked by At

to get the spherical coordinates (theta, phi and alpha) i use this code:

double phi_rad = atan2f(z,sqrt((x*x)+(y*y)));
double theta_rad = atan2f(y, x);
double r = sqrt((x*x)+(y*y)+(z*z));

And to map theta to 0-360 degrees i use this code:

double theta_deg = (theta_rad/M_PI*180) + (theta_rad > 0 ? 0 : 360);

But how can i map phi to 0-360 degrees? I tryed the same principle as i used for theta_deg but it dont work really fine.

1

There are 1 answers

4
Tom Fenech On

If phi is your azimuthal angle (0 to 2π) and theta is your polar angle (0 to π), you can do:

double phi_rad = atan2(y,x);
double theta_rad = acos(z);

Then you can just convert from radians to degrees using the standard:

double rad2deg(double rad)
{
    return rad * 180.0 / M_PI;
}