Eri*_*ier 18 math trigonometry angle
我想反转sin/ cos操作以恢复一个角度,但我无法弄清楚我应该做什么.
我已经使用sin和cos以弧度为单位的角度来获得x/y向量:
double angle = 90.0 * M_PI / 180.0; // 90 deg. to rad.
double s_x = cos( angle );
double s_y = sin( angle );
Run Code Online (Sandbox Code Playgroud)
鉴于s_x并且s_y,才可能找回角度?我认为atan2是使用的功能,但我没有得到预期的结果.
我使用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;
Run Code Online (Sandbox Code Playgroud)
对于(s_y == 0)的特定情况,取+ acos或-acos无关紧要,因为它意味着角度为0°(+ 0°或-0°是相同的角度)或180°(+ 180) °或-180°是相同的角度).