【问题标题】:How can i map both angles (theta and phi) of the spherical coordinates to 360 degrees如何将球坐标的两个角度(theta 和 phi)映射到 360 度
【发布时间】:2013-12-13 10:55:11
【问题描述】:

要获得球面坐标(theta、phi 和 alpha),我使用以下代码:

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));

为了将 theta 映射到 0-360 度,我使用以下代码:

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

但是我如何将 phi 映射到 0-360 度?我尝试了与 theta_deg 相同的原理,但效果并不好。

【问题讨论】:

    标签: math atan2


    【解决方案1】:

    如果 phi 是您的方位角(0 到 2π),theta 是您的极角(0 到 π),您可以这样做:

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

    然后您可以使用标准将弧度转换为度数:

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

    【讨论】:

    • 极角也不能映射到0-360度?我知道您可以用极角范围从 0 到 π 来描述球坐标系中的所有点。但我必须将其映射到 0 到 2π 的范围内。
    • 如果极角可以从0到360,那么方位角应该只能从0到180。这是你想要的吗?
    • 不,我需要从 0 到 360 的两个角度。
    • 在这种情况下,每个 (x, y, z) 都会有两个等价的 (theta, phi) 映射。也许您可以详细说明您的问题?
    猜你喜欢
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    相关资源
    最近更新 更多