The MathF.Atan2() method in C# returns the angle whose tangent is the quotient of two floating-point numbers.
Syntax
Following is the syntax −
public static float Atan2 (float val1, float val2);
Above, val1 is the x-coordinate of a point, whereas val2 is the y-coordinate.
Example
Let us now see an example to implement the MathF.Atan2() method −
using System;
public class Demo {
public static void Main(){
float val1 = 0.1f;
float val2 = 0.9f;
Console.WriteLine("Return value = "+(MathF.Atan2(val1,val2)));
}
}Output
This will produce the following output −
Return value = 0.1106572
Example
Let us now see another example to implement the MathF.Atan2() method −
using System;
public class Demo {
public static void Main(){
float val1 = 25f;
float val2 = 25f;
Console.WriteLine("Return value = "+(MathF.Atan2(val1,val2))* (180 / MathF.PI));
}
}Output
This will produce the following output −
Return value = 45