Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/math/atan2"

From cppreference.com
< cpp‎ | numeric‎ | math
m (Shorten template names. Use {{lc}} where appropriate.)
m (Update links.)
Line 58: Line 58:
  
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/numeric/math/dcl list atan}}
+
{{dsc inc | cpp/numeric/math/dsc atan}}
{{dsc inc | cpp/numeric/math/dcl list asin}}
+
{{dsc inc | cpp/numeric/math/dsc asin}}
{{dsc inc | cpp/numeric/math/dcl list acos}}
+
{{dsc inc | cpp/numeric/math/dsc acos}}
{{dsc inc | cpp/numeric/math/dcl list tan}}
+
{{dsc inc | cpp/numeric/math/dsc tan}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 22:16, 31 May 2013

 
 
 
 
Defined in header <cmath>
float       atan2( float y, float x );
(1)
double      atan2( double y, double x );
(2)
long double atan2( long double y, long double x );
(3)
Promoted    atan2( Arithmetic y, Arithmetic x );
(4) (since C++11)

Computes the inverse tangent of y/x using the signs of arguments to correctly determine quadrant.

4) If any argument has integral type, it is cast to double. If any other argument is long double, then the return type is long double, otherwise it is double.

Contents

Parameters

x, y - floating point value

Return value

Arc tangent of y/x in radians in the range of [-π; π] radians.

Y argument
Return value
math-atan2.png
X argument

Example

#include <cmath>
#include <utility>
#include <iostream>
 
std::pair<double, double> cartesian_to_polar(double x, double y)
{
    return {std::hypot(x, y), std::atan2(y,x)};
}
 
int main()
{
    std::pair<double, double> polar = cartesian_to_polar(1, 1);
    std::cout << "(1,1) cartesian is (" << polar.first
               << "," << polar.second<< ") polar\n";
}

Output:

(1,1) cartesian is (1.41421,0.785398) polar


See also

(C++11)(C++11)
computes arc tangent (arctan(x))
(function) [edit]
(C++11)(C++11)
computes arc sine (arcsin(x))
(function) [edit]
(C++11)(C++11)
computes arc cosine (arccos(x))
(function) [edit]
(C++11)(C++11)
computes tangent (tan(x))
(function) [edit]