The ratios we most commonly use in trigonometry include sine, cosine, tangent, etc. You can use angles to calculate these ratios. If we know the ratio value, we can also calculate the angle using inverse trigonometric functions.
This lesson will show you how to use C's arctangent (arctan) function to calculate an angle using its tangent value in radians.
Compute angles using the atan() technique and the inverse trigonometric tangent function. The C standard library contains this function. Before using this method, we must import the cmath library. This method returns the angle in radians and takes the tangent value as an argument. The following uses simple syntax -
#include < cmath > atan( <tangent value> )
The cosine value must be in the range [-infinity to infinity]. The range of return values is $\mathrm{[-\:\frac{\pi}{2},\frac{\pi}{2}]}$ (both inclusive)
#include <iostream> #include <cmath> using namespace std; float solve( float x ) { float answer; answer = atan( x ); return answer; } int main() { float angle, ang_deg; angle = solve( 1 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given tangent value 1 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 0 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given tangent value 0 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 999999 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given tangent value 999999 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( -999999 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given tangent value -999999 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; }
The angle (in radian) for given tangent value 1 is: 0.785398 = 45 (in degrees) The angle (in radian) for given tangent value 0 is: 0 = 0 (in degrees) The angle (in radian) for given tangent value 999999 is: 1.5708 = 90 (in degrees) The angle (in radian) for given tangent value -999999 is: -1.5708 = -90 (in degrees)
The atan() method receives the tangent value in this case and returns the angle in radian format. We convert this output from radians to degrees using the formula below.
$$\mathrm{\theta_{deg}\:=\:\theta_{rad}\:\times\:\frac{180}{\pi}}$$
To perform inverse trigonometric operations based on cosine values, we use the acos() function from the cmath library. This function takes a cosine value as input and returns the given angle in radians. In older versions of C/C, the return type was double, but later C versions used additional overloads of float and long-double. When an integer value is passed as a parameter, it converts the input parameter to double and calls the acos() method corresponding to the double type parameter.
The above is the detailed content of C++ program to find the arc tangent of a given value. For more information, please follow other related articles on the PHP Chinese website!