MathF.Atan() Method in C# with Examples

The MathF.Atan() method in C# is used to return the angle whose tangent is given as a float value argument. This method returns the arctangent (inverse tangent) of the specified number, with the result expressed in radians between -?/2 and ?/2.

Syntax

Following is the syntax for the MathF.Atan() method −

public static float Atan (float val);

Parameters

  • val − A float representing a tangent value. This parameter can be any real number including positive infinity, negative infinity, or NaN (Not a Number).

Return Value

The method returns a float value representing the angle in radians. The return value ranges from -?/2 to ?/2, or NaN if the input is NaN.

MathF.Atan() Function Behavior tan?¹(0.1) tan?¹(0.9) -?/2 ?/2 Output Range Input: Any real number Output: -1.57 to 1.57 radians

Example 1

Let us see an example demonstrating the MathF.Atan() method with different float values −

using System;

public class Demo {
   public static void Main() {
      float val1 = 1.2f;
      float val2 = 45.5f;
      Console.WriteLine("Angle (val1) = " + (MathF.Atan(val1)));
      Console.WriteLine("Angle (val2) = " + (MathF.Atan(val2)));
      
      // Converting radians to degrees for better understanding
      Console.WriteLine("Angle (val1) in degrees = " + (MathF.Atan(val1) * 180 / MathF.PI));
      Console.WriteLine("Angle (val2) in degrees = " + (MathF.Atan(val2) * 180 / MathF.PI));
   }
}

The output of the above code is −

Angle (val1) = 0.876058
Angle (val2) = 1.548822
Angle (val1) in degrees = 50.19443
Angle (val2) in degrees = 88.72504

Example 2

Let us see another example with smaller tangent values −

using System;

public class Demo {
   public static void Main() {
      float val1 = 0.1f;
      float val2 = 0.9f;
      Console.WriteLine("Angle (val1) = " + (MathF.Atan(val1)));
      Console.WriteLine("Angle (val2) = " + (MathF.Atan(val2)));
      
      // Special cases
      Console.WriteLine("Atan(0) = " + MathF.Atan(0f));
      Console.WriteLine("Atan(1) = " + MathF.Atan(1f));
      Console.WriteLine("Atan(infinity) = " + MathF.Atan(float.PositiveInfinity));
   }
}

The output of the above code is −

Angle (val1) = 0.09966865
Angle (val2) = 0.7328151
Atan(0) = 0
Atan(1) = 0.7853982
Atan(infinity) = 1.570796

Common Use Cases

The MathF.Atan() method is commonly used in:

  • Coordinate geometry − Finding angles in coordinate systems

  • Physics calculations − Computing angles from velocity components

  • Computer graphics − Calculating rotation angles and vector directions

Conclusion

The MathF.Atan() method calculates the arctangent of a float value, returning the angle in radians between -?/2 and ?/2. It is essential for trigonometric calculations where you need to find an angle from its tangent value, commonly used in geometry, physics, and graphics programming.

Updated on: 2026-03-17T07:04:36+05:30

150 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements