关于数学:将atan2值转换为标准的360度系统值

Convert atan2 value to standard 360-degree-system value

可以说我正在使用atan2来获取两个向量之间的角度。

atan2给出一个以弧度为单位的值。 我使用Java中的内置函数将其转换为度。 这给了我一个在0180度之间或在0-180之间的值(atan2的性质)。

有没有一种方法可以将通过此函数接收的值(转换为度数之后)转换为标准的360度系统,而无需更改角度-仅采用写入的方式? 这将使我的工作更加轻松。

谢谢


尝试这个:

1
2
3
4
5
double theta = Math.toDegrees(atan2(y, x));

if (theta < 0.0) {
    theta += 360.0;
}


要将其转换为北参考0-360度的值,请执行以下操作:

1
2
3
4
5
6
double degrees = 90.0d - Math.toDegrees( Math.atan2( y, x ) );

if( degrees < 0.0d )
{
   degrees += 360.0;
}

角度范围为0到360度的公式。

1
f(x,y)=180-90*(1+sign(x))* (1-sign(y^2))-45*(2+sign(x))*sign(y)
1
-(180/pi())*sign(x*y)*atan((abs(x)-abs(y))/(abs(x)+abs(y)))

根据我在Trig类上学到的知识,以上答案是错误的。 例如,如果矢量交点(-1,-1)的角度为225度(标准位置),则切线将为正1,这将产生45度的反正切。 上述解决方案将不会注意到这一点,并且矢量的角度将是错误的。 这就是反正切公式根据情况而不同的原因。 您必须先确定将要到达的角度。

Recall that we can apply trig functions to any angle, including large and negative angles. But when we consider the inverse function we run into a problem, because there are an infinite number of angles that have the same tangent. For example 45° and 360+45° would have the same tangent. For more on this see Inverse trigonometric functions.

To solve this problem, the range of inverse trig functions are limited in such a way that the inverse functions are one-to-one, that is, there is only one result for each input value.

来自http://www.mathopenref.com/arctan.html