Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C+中基于三角函数求角+;_C++_Trigonometry_Angle - Fatal编程技术网

C++ 如何在C+中基于三角函数求角+;

C++ 如何在C+中基于三角函数求角+;,c++,trigonometry,angle,C++,Trigonometry,Angle,我知道我可以通过数学得到给定角度的三角函数。我在想,是否可以反向进行 假设有一个有两个坐标的向量。我有它的x和y值,所以切线可以很容易地计算出来 float tg; if(x != 0) { tg = y/x } else { //vector is vertical and it doesn't have a tangent //handle this somehow } 然而,我看不出有任何相反的做法。我需要一种方法,根据切线获得0到2pi之间的角度。使用函数ang

我知道我可以通过数学得到给定角度的三角函数。我在想,是否可以反向进行

假设有一个有两个坐标的向量。我有它的x和y值,所以切线可以很容易地计算出来

float tg;
if(x != 0)
{
    tg = y/x
}
else
{
    //vector is vertical and it doesn't have a tangent
    //handle this somehow
}

然而,我看不出有任何相反的做法。我需要一种方法,根据切线获得0到2pi之间的角度。

使用函数
angle=atan2(y,x)
以下是指向更多信息的链接:


(使用x==0作为奖励)。这在数学上称为反正切,通常缩写为atan。假设您知道数学函数的存在,这是一个非常冗长的问题,可以大大改进到可以用谷歌搜索的程度。@OJFord实际上我5年前还没有意识到:)我建议将