Mono Class Library: System.Math Overview | Members

System.Math.Atan2 Method

Returns the angle whose tangent is the quotient of two specified double values. [Edit]

public static double Atan2 (double y, double x)

Parameters

y
A double representing the y coordinate of a point. [Edit]
x
A double representing the x coordinate of a point. [Edit]

Returns

A double containing the value of an angle, theta, measured in radians, such that -pi <= theta <= pi and tantheta = y/x, where (x, y) is a point in the Cartesian plane.

If both x and y are any combination of double.NegativeInfinity and double.PositiveInfinity, double.NaN is returned.

If either x or y is equal to double.NaN, double.NaN is returned.

The following table specifies the return value if x or y is equal to double.NegativeInfinity or double.PositiveInfinity.

ConditionReturn Value

y is equal to double.PositiveInfinity or double.NegativeInfinity, and

x is equal to double.PositiveInfinity or double.NegativeInfinity.

double.NaN.

y is equal to double.NegativeInfinity, and

x is not equal to double.PositiveInfinity or double.NegativeInfinity.

-Math.PI/2.

y is equal to double.PositiveInfinity, and

x is not equal to double.PositiveInfinity or double.NegativeInfinity.

Math.PI/2.

x is equal to double.PositiveInfinity, and

y is not equal to double.PositiveInfinity or double.NegativeInfinity.

0.

x is equal to double.NegativeInfinity, and

y >= 0 and not equal to double.PositiveInfinity.

Math.PI.

x is equal to double.NegativeInfinity, and

y < 0 and not equal to double.NegativeInfinity.

-Math.PI.
[Edit]

Remarks

The return value is the angle in the Cartesian plane formed by the x-axis, and a vector starting from the origin, (0,0), and terminating at the point, (x,y).

Note:
  • For (x, y) in quadrant 1, 0 < theta < pi/2.
  • For (x, y) in quadrant 2, pi/2 < theta < pi.
  • For (x, y) in quadrant 3, -pi < theta < -pi/2.
  • For (x, y) in quadrant 4, -pi/2 < theta < 0.
[Edit]

Example

The following example demonstrates using the Math.Atan2(double, double) method.

C# Example
using System;

public class MathAtan2Example
{

   public static void Main()
   {

      Double d1 = Math.Atan2(2,0);
      Double d2 = Math.Atan2(0,0);
      Console.WriteLine("Math.Atan2(2,0) returns {0}", d1);
      Console.WriteLine("Math.Atan2(0,0) returns {0}", d2);

   }

}

The output is

Math.Atan2(2,0) returns 1.5707963267949
Math.Atan2(0,0) returns 0

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0