1

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.

Schulle
  • 162
  • 1
  • 8

1 Answers1

0

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;
}
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • It is also not possible to map the polar angle to 0-360 degrees? I know that you can describe all points in a spherical coordinate system with a polar angle range from 0 to π. But I must map it to a range from 0 to 2π. – Schulle Dec 13 '13 at 11:23
  • If the polar angle can go from 0 to 360, the the azimuthal angle should only go from 0 to 180. Is that what you want? – Tom Fenech Dec 13 '13 at 11:26
  • No I need two angles from 0 to 360. – Schulle Dec 13 '13 at 11:31
  • In that case, there would be two equivalent (theta, phi) mappings for every (x, y, z). Maybe you can elaborate on your problem? – Tom Fenech Dec 13 '13 at 12:50