如何根据三角函数获得角度C++

How to get angle based on trigonometric function in C++

本文关键字:C++ 何根 三角函数      更新时间:2023-10-16

我知道我可以通过math.h得到给定的角度三角函数。我想知道,是否可以反向完成。

假设有一个具有两个坐标的向量。我有它的 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)以下是指向更多信息的链接:http://www.cplusplus.com/reference/cmath/atan2/

http://en.cppreference.com/w/cpp/numeric/math/atan2