TechArena Community The atan2() function of C++

#1
10-03-2010
 Member Join Date: Dec 2009 Posts: 31
The atan2() function of C++

I am the studying in the BSC-IT. I can have the good knowledge of the C++ language. But I can not have much more knowledge about the built-in functions of C++ language. So, I want to know about the atan2() function of the C++ language. I also want to know about how can I use the atan2() function in the C++ programming language. Thus, Can anyone has the proper answer on the atan2() function in the C++ language. Reply Me!!!
#2
10-03-2010
 Member Join Date: May 2008 Posts: 2,008
Re: The atan2() function of C++

The atan2() function of the C++ language can be used to compute an arc of a tangent with two arguments. The atan2() function can returns the principal value of an arc tangent of q/p that can be an expressed in radians. To calculate the value, the function that can uses the sign of both an arguments to determine the quadrant. In C++ language, the atan2() function can be overloaded in the <valarray>.
#3
10-03-2010
 Member Join Date: May 2008 Posts: 2,293
Re: The atan2() function of C++

The atan2() function can compute an arc of the tangent with two arguments. The atan2() function of the C++ can returns the principal value of an arc of the tangent of b/a and that can be an expressed in radians. The following can be the general syntax of the atan2() function of the C++ language :
Code:
```double atan2 (      double q,      double p );
long double atan2 ( long double q, long double p );
float atan2 (       float q,       float p );```
#4
10-03-2010
 Member Join Date: Apr 2008 Posts: 1,948
The atan2() function of C++

The following program could states you that how you can use the atan2() function in the C++ language coding while using the atan2() function in the coding as shown :
Code:
```#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double p, q, rslt;
p = -10.0;
q = 10.0;
result = atan2 (q,p) * 180 / PI;
printf ("The arc tangent for (p=%lf, q=%lf) is %lf degrees\n", p, q, rslt);
return 0;
}```
Output:
Code:
`The arc tangent for (p=-10.000000, q=10.000000) is 135.000000 degrees.`
#5
10-03-2010
 Member Join Date: Apr 2008 Posts: 2,001
Re: The atan2() function of C++

The atan2() function can calculates an arc of the tangent of q/p, by using the signs of an arguments to calculate the quadrant of the return value. The values that can be returned can be in the given specified range [-pi, pi]. You have to noticed that an order of the given specified an arguments can be passed to the atan2() function.
#6
10-03-2010
 Member Join Date: Nov 2005 Posts: 1,323
Re: The atan2() function of C++

I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the atan2() function in the C++ programming as follows :
Code:
```#include <math.h>
#include <stdio.h>
#include <errno.h>
int main( int ac, char* av[] )
{
double z1, z2, z;
if( ac != 3 )
{
fprintf( stderr, "Usage: %s <z1> <z2>\n", av[0] );
return;
}
z1 = atof( av[1] );
z = atan( z1 );
printf( "Arctangent of %f: %f\n", z1, z );
z2 = atof( av[2] );
z = atan2( z1, z2 );
printf( "Arctangent of %f / %f: %f\n", z1, z2, z );
}```
Output
Code:
```Arctangent of 0.500000: 0.463648
Arctangent of 0.500000 / 5.000000: 0.099669```

 Tags: