<valarray>
template<class T> valarray<T> atan2 (const valarray<T>& y, const valarray<T>& x);
template<class T> valarray<T> atan2 (const valarray<T>& y, const T& x);
template<class T> valarray<T> atan2 (const T& y, const valarray<T>& x);
Compute atan2 of valarray elements
Returns a valarray object containing the principal value of the arc tangent of all the elements. The tangent for which it is calculated is the quotient of coordinates y/x, using their signed to determine the appropriate quadrant.
This function overloads cmath's atan2 function.
Parameters
- y
- valarray or element with the y coordinate(s).
- x
- valarray or element with the x coordinate(s).
Return value
A valarray object with the arc tangent values of y/x.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// atan2 valarray example
#include <iostream>
#include <cmath>
#include <valarray>
using namespace std;
int main ()
{
double y[] = {0.0, 3.0, -2.0};
double x[] = {-3.0, 3.0, -1.0};
valarray<double> ycoords (y,3);
valarray<double> xcoords (x,3);
valarray<double> results = atan2 (ycoords,xcoords);
cout << "results: ";
for (size_t i=0; i<results.size(); ++i)
cout << results[i] << ' ';
cout << endl;
return 0;
}
|
Output:
results: 3.14159 0.785398 -2.03444
|
See also
atan | Compute arc tangent of valarray elements (function template) |
tan | Compute tangent of valarray elements (function template) |
|