atan2() function

tan2(): This function computes the arc tangent with two parameters. It returns the principal value of the arc tangent of y/x, expressed in radians.

The function atan2() takes two arguments: x-coordinate and y-coordinate.

1. x - this value represents the proportion of the x-coordinate.

2. y - this value represents the proportion of the y-coordinate.

The atan2() function returns the value in the range of [-π, π]. If both x and y are zero, the atan2() function returns 0.

Example 1: In radians

Input:  x=10.0, y=-5.0
Output: -0.463648

Example 2: In degrees

Input:  x=10.0 y=-5.0
Output: -26.5785

Approach 1: In radians

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double x = 10.0, y = -5.0;

    cout << atan2(y, x);

    return 0;
}

Approach 2: In degrees

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double x = 10.0y = -5.0;

    double radian = atan2(yx);

    double degrees = radian * 180 / 3.14;
    cout << degrees << "\n";

    return 0;
}


No comments:

Post a Comment