Skip to content
Related Articles

Related Articles

Improve Article
MathF.Atan2() Method in C# with Examples
  • Last Updated : 04 Apr, 2019

MathF.Atan2(Single, Single) Method is used to return the angle whose tangent is the quotient of two specified numbers. Basically, it returns an angle θ (measured in radian) whose value lies between -π and π. This is a counterclockwise angle lies between the positive x-axis, and the point (x, y).

Syntax: public static float Atan2 (float y, float x);

Parameters:
y: The y coordinate of a point of type System.Single.
x: The x coordinate of a point System.Single.

Return Value: This method returns the angle Θ of type System.Single.

Note: An angle, θ(measured in radians), such that -π ≤ θ ≤ π, and tan(θ) = value1 / value2, where (value1, value2) are the points in the cartesian plane. There are two conditions for the return values:



  • When the points lies in the Cartesian plane
  • When the points lies on the boundaries of the quadrants

Example 1:




// C# program to demonstrate the 
// MathF.Atan2(Single, Single) Method
using System; 
    
class Geeks { 
       
    // Main method 
    public static void Main() 
    
        // using MathF.Atan2(Single, Single) Method 
        // and converting result into degree 
        Console.Write(MathF.Atan2(10f, 10f) * (180 / MathF.PI)); 
    
Output:
45

Example 2:




// C# program to demonstrate the 
// MathF.Atan2(Single, Single) Method
using System; 
    
class Geeks { 
       
    // Main method 
    public static void Main() 
    
        // using MathF.Atan2(Single, Single) Method 
        // and converting result into degree 
        Console.Write(MathF.Atan2(0f, -7f) * (180 / MathF.PI)); 
    
Output:
180



My Personal Notes arrow_drop_up
Recommended Articles
Page :