本文介绍了从sin/cos转换中找回角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想反转sin
/cos
操作以恢复角度,但是我不知道该怎么做.
I want to reverse a sin
/cos
operation to get back an angle, but I can't figure out what I should be doing.
我以弧度为角度使用sin
和cos
来获取x/y向量,如下所示:
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 );
给出s_x
和s_y
,是否可以找回角度?我以为atan2
是要使用的函数,但没有得到预期的结果.
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.
推荐答案
atan2(s_y, s_x)
应该给您正确的角度.也许您已经颠倒了s_x
和s_y
的顺序.另外,您可以分别在s_x
和s_y
上直接使用acos
和asin
函数.
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.
这篇关于从sin/cos转换中找回角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!