28

我想反转sin/cos操作以恢复角度,但我不知道我应该做什么。

我已经使用sincos以弧度为单位来获得 x/y 向量,如下所示:

double angle = 90.0 * M_PI / 180.0;  // 90 deg. to rad.
double s_x = cos( angle );
double s_y = sin( angle );

给定s_xand s_y,是否有可能恢复角度?我认为atan2是要使用的功能,但我没有得到预期的结果。

4

5 回答 5

29

atan2(s_y, s_x)应该给你正确的角度。也许你颠倒了s_xand的顺序s_y。此外,您可以分别在和上直接使用acosasin函数。s_xs_y

于 2012-12-29T06:05:50.553 回答
10

我使用acos函数从给定的 s_x cosinus 取回角度。但是因为多个角度可能导致相同的余弦(例如 cos(+60°) = cos(-60°) = 0.5),所以不可能直接从 s_x 取回角度。所以我也使用s_y 的符号来取回角度的符号。

// Java code
double angleRadian = (s_y > 0) ? Math.acos(s_x) : -Math.acos(s_x);
double angleDegrees = angleRadian * 180 / Math.PI;

对于 (s_y == 0) 的特定情况,取 +acos 或 -acos 无关紧要,因为这意味着角度是 0°(+0° 或 -0° 是相同的角度)或 180°(+180 ° 或 -180° 是相同的角度)。

于 2014-05-23T10:38:00.207 回答
2

asin(s_x), acos(s_y),也许,如果你使用的是 c。

于 2012-12-29T06:09:56.330 回答
2

在数学中是 sin 和 cos 的逆运算。这是 arcsin 和 arccos。不知道你用的是什么编程语言。但通常如果它具有 cos 和 sin 函数,那么它可以具有反向函数。

于 2012-12-29T06:07:15.430 回答
1
double angle_from_sin_cos( double sinx, double cosx ) //result in -pi to +pi range
{
    double ang_from_cos = acos(cosx);
    double ang_from_sin = asin(sinx);
    double sin2 = sinx*sinx;
    if(sinx<0)
    {
        ang_from_cos = -ang_from_cos;
        if(cosx<0) //both negative
            ang_from_sin = -PI -ang_from_sin;
    }
    else if(cosx<0)
        ang_from_sin = PI - ang_from_sin;
    //now favor the computation coming from the
    //smaller of sinx and cosx, as the smaller
    //the input value, the smaller the error
    return (1.0-sin2)*ang_from_sin + sin2*ang_from_cos;
}
于 2021-04-08T16:59:44.153 回答