In C++, the atan2() function is defined in the <cmath> or <math.h> header file and is used to calculate the inverse tangent of the ratio y/x. Unlike the atan() function, atan2() considers the signs of both coordinates to determine the correct quadrant of the angle.
The atan2() function is commonly used in trigonometry, navigation, robotics, computer graphics, and geometry to determine the angle of a point relative to the origin. The returned angle is expressed in radians.
It has the following syntax.
Suppose the coordinate is (x,y). Syntax would be:
y: It represents the y-coordinate value.
x: It represents the x-coordinate value.
It returns the value in the range[-?, ?] and if the values of both x and y are zero then it returns zero value.
Here, we are going to discuss several examples to demonstrate the List atan2() Function Function.
This example demonstrates how the atan2() function behaves when both x and y coordinates are zero.
Output:
Value of tan(y/x) is : 0 Value of tan-1(y/x) is : 0
Explanation:
In this example, atan2() calculates the inverse tangent when both 'x' and 'y' are zero.
This example demonstrates how the atan2() function works when the x-coordinate is of integer type and the y-coordinate is of float type.
Output:
Value of tan(y/x) is : 3.6021 Value of tan1(y/x) is : 0.915101
Explanation:
In this example, atan2() function finds the inverse of a tangent when x is of integer type and y is of float type.
Output:
Value of tan(y/x) is : -2.18504 Value of tan-1(y/x) is : 1.10715
Explanation:
This example demonstrates how to calculate the inverse tangent for positive x and y coordinates using the atan2() function.
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India