C# Math Atan2
Description
Math Atan2
returns the angle whose tangent is the quotient
of two specified numbers.
Syntax
Math.Atan2
has the following syntax.
public static double Atan2(
double y,
double x
)
Parameters
Math.Atan2
has the following parameters.
y
- The y coordinate of a point.x
- The x coordinate of a point.
Returns
Math.Atan2
method returns
Example
The following code shows how to use Math.Atan2 method.
using System;// ww w . j a v a2 s. co m
class Sample
{
public static void Main()
{
double x = 1.0;
double y = 2.0;
double angle;
double radians;
double result;
// Calculate the tangent of 30 degrees.
angle = 30;
radians = angle * (Math.PI/180);
result = Math.Tan(radians);
Console.WriteLine("The tangent of 30 degrees is {0}.", result);
// Calculate the arctangent of the previous tangent.
radians = Math.Atan(result);
angle = radians * (180/Math.PI);
Console.WriteLine("The previous tangent is equivalent to {0} degrees.", angle);
}
}
The code above generates the following result.