C Standard Libraries C++

atan2()

Declaration

double atan2(double dY, double dX);

Description

This function returns the inverse tangent of the passed-in arguments. The first argument is the sine or y value and the second argument is the cosine or x value. The atan(y/x) function is the equivalent of atan2(y, x), except that atan() cannot handle the case where x = 0. The function atan2 has the advantage over atan in that x values can be zero, which allows it to compute angles around the entire unit circle.

Overloads

float atan2(float, float);
double atan2(double, double);
long double atan2(long double, long double);

Related Functions

float atan2f(float, float);
long double atan2l(long double, long double);

* Note: Since C does not allow function overloading, these other versions of this function exist.

Domain

(-∞, ∞) x (-∞, ∞)

Range

(-Π, Π]

Periodicity

None

Symmetry

None

Asymptotes

None

 

Example

#include <iostream>
#include <cmath>

int main() {
    using namespace std;

    // Point in the first quadrant
    double dX = 4.3;
    double dY = 5.3;
    cout << "x = " << dX << " y = " << dY << " atan2(y, x) = " << atan2(dY, dX) << endl;

    // Point in the second quadrant
    dX = -12.2;
    dY = 6.0;
    cout << "x = " << dX << " y = " << dY << " atan2(y, x) = " << atan2(dY, dX) << endl;

    // Point in the third quadrant
    dX = -4.0;
    dY = -3.0;
    cout << "x = " << dX <<
        " y = " << dY <<
        " atan2(y, x) = " << atan2(dY, dX) << endl;

    // Point in the fourth quadrant
    dX = 2.8;
    dY = -1.0;
    cout << "x = " << dX << " y = " << dY << " atan2(y, x) = " << atan2(dY, dX) << endl;

    return 0;
}

Output

atan2() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.