Getting angle back from a sin/cos conversion

浪子不回头ぞ 提交于 2019-12-21 06:58:17

问题


I want to reverse a sin/cos operation to get back an angle, but I can't figure out what I should be doing.

I have used sin and cos on an angle in radians to get the x/y vector as such:

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

Given s_x and s_y, is it possible to get back the angle? I thought atan2 was the function to use, but I'm not getting the expected results.


回答1:


atan2(s_y, s_x) should give you the correct angle. Maybe you have reversed the order of s_x and s_y. Also, you can use the acos and asin functions directly on s_x and s_y respectively.




回答2:


I use the acos function to get back the angle from the given s_x cosinus. But because several angles may result to the same cosinus (for example cos(+60°) = cos(-60°) = 0.5), it's not possible to get back the angle directly from s_x. So I also use the sign of s_y to get back the sign of the angle.

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

for the specific case of (s_y == 0), it does not matter to take +acos or -acos because it means the angle is 0° (+0° or -0° are the same angles) or 180° (+180° or -180° are the same angles).




回答3:


In math is reverse operation for sin and cos. This is arcsin and arccos. I don't know what programming language you use. But usually if it have cos and sin function then it can have reverse function.




回答4:


asin(s_x), acos(s_y), perhaps, if you are using c.



来源:https://stackoverflow.com/questions/14079127/getting-angle-back-from-a-sin-cos-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!