Math.Atan2() Method in C#


The Math.Atan2() method in C# is used to return the angle whose tangent is the quotient of two specified numbers.

Syntax

Following is the syntax −

public static double Atan2 (double val1, double val2);

Above, val1 is the y coordinate, whereas val2 is the x coordinate.

Example

Let us now see an example to implement Math.Atan2() method −

using System;
public class Demo {
   public static void Main(){
      double val1 = 3.0;
      double val2 = 1.0;
      double angle, radians;
      radians = Math.Atan2(val1, val2);
      angle = radians * (180/Math.PI);
      Console.WriteLine("Result = "+angle);
   }
}

Output

This will produce the following output −

Result = 71.565051177078

Example

Let us see another example to implement Math.Atan2() method −

using System;
public class Demo {
   public static void Main(){
      double val1 = 0;
      double val2 = 5;
      double angle, radians;
      radians = Math.Atan2(val1, val2);
      angle = radians * (180/Math.PI);
      Console.WriteLine("Result = "+angle);
   }
}

Output

This will produce the following output −

Result = 0

Updated on: 07-Nov-2019

253 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements