Double - Atan2
Returns the angle whose tangent is the quotient of two specified numbers.
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); }
View Source
using System; public static partial class Extensions { /// <summary> /// Returns the angle whose tangent is the quotient of two specified numbers. /// </summary> /// <param name="y">The y coordinate of a point.</param> /// <param name="x">The x coordinate of a point.</param> /// <returns> /// An angle, ?, measured in radians, such that -?????, and tan(?) = / , where (, ) is a point in the Cartesian /// plane. Observe the following: For (, ) in quadrant 1, 0 < ? < ?/2.For (, ) in quadrant 2, ?/2 < /// ???.For (, ) in quadrant 3, -? < ? < -?/2.For (, ) in quadrant 4, -?/2 < ? < 0.For points on the /// boundaries of the quadrants, the return value is the following:If y is 0 and x is not negative, ? = 0.If y is /// 0 and x is negative, ? = ?.If y is positive and x is 0, ? = ?/2.If y is negative and x is 0, ? = -?/2.If or /// is , or if and are either or , the method returns . /// </returns> public static Double Atan2(this Double y, Double x) { return Math.Atan2(y, x); } }