C# Tutorial C# Advanced C# Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C# - Math Atan2() Method

The C# Math Atan2() method returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). The return value will be in the range -𝜋 through 𝜋. In special cases it returns the following:

  • If either argument is NaN, the method returns NaN.
  • If any of the arguments are either PositiveInfinity or NegativeInfinity, the method returns NaN.


public static double Atan2 (double y, double x);


y Specify the ordinate coordinate.
x Specify the abscissa coordinate.

Return Value

Returns theta of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates.


In the example below, Atan2() method is used to calculate the theta of a point.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine(Math.Atan2(10, 10)); 
    Console.WriteLine(Math.Atan2(20, 10)); 
    Console.WriteLine(Math.Atan2(-20, 10)); 

The output of the above code will be:


❮ C# Math Methods