Sine, cosine, tangent, and a few more ratios are some of the ones we utilize the most in trigonometry. These ratios can be computed from an angle. However, we can also determine the angle using inverse trigonometric functions if we know the ratio values.
在本教程中,我们将介绍如何使用C++的反余弦(arccosine)函数将余弦值转换为弧度角。
The acos() function
反余弦函数被用来使用acos()方法计算角度。这个函数可以在C++标准库中找到。为了使用这个方法,我们必须导入cmath库。这个函数接受余弦值作为参数,并返回以弧度为单位的角度。下面使用简单的语法:
Syntax
#include
acos( )
登录后复制
The cosine value must be in the range [-1 to +1] (both included). Otherwise, a domain error will be raised, and it will return Not-A-Number (nan). The returned value will be in the range [0, π] (both included)
算法
- 将余弦值 x 作为输入
- 使用 acos( x ) 来计算 cos−1(x)
- Return result.
Example
#include
#include
using namespace std;
float solve( float x ) {
float answer;
answer = acos( x );
return answer;
}
int main()
{
float angle, ang_deg;
angle = solve( 0.7071067 );
ang_deg = angle * 180 / 3.14159;
cout