CSharp · Console
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002324/double-atan2
// @nuget: Z.ExtensionMethods
using System;
public class Program
{
public static void Main()
{
double x = 1.0;
double y = 2.0;
double angle;
double radians;
// Calculate the tangent of 30 degrees.
angle = 30;
radians = angle * (Math.PI / 180);
// C# Extension Method: Double - Atan2
radians = y.Atan2(x);
angle = radians * (180 / Math.PI);
Console.WriteLine("The arctangent of the angle formed by the x-axis and ");
Console.WriteLine("a vector to point ({0},{1}) is {2}, ", x, y, radians);
Console.WriteLine("which is equivalent to {0} degrees.", angle);
}
}