Arc tangent function in C #

4

I made the following calculations on the calculator:

arctg(50/10) = 78,69°

However, when doing in code, using the function Math.Atan , the result is as follows:

Is there any other way to do the Tangent Arch calculation?

    
asked by anonymous 16.02.2017 / 20:16

2 answers

9

The documentation says that the entry of the method must be in radians and you are using degrees. Must convert radian to degree before. The calculator is already in degrees, so it worked.

using static System.Console;
using static System.Math;

public class Program {
    public static void Main() {
        WriteLine(Atan(5) * 180 / PI);
    }
}

See running on .NET Fiddle . And at Coding Ground . Also I put it in GitHub for future reference .

You may want to create functions to do the conversion:

public static class MathUtil {
    public static double DegreeToRadian(double angle) => PI * angle / 180.0;
    public static double RadianToDegree(double angle) => angle * (180.0 / PI);
}

See working on .NET Fiddle . And No Coding Ground . Also I put it in GitHub for future reference .

Related .

    
16.02.2017 / 20:42
5

You still need to get the result of the operation ( Math.Atan ) and multiply by division of 180 and the constant PI , example , to get the value in Degrees :

int t = 50;
int p = 10;
double r = t / p;

var resultado = Math.Atan(r);
resultado = resultado * (180 / Math.PI);

System.Console.WriteLine(resultado);
System.Console.ReadKey();

Output:

78,6900675259798

Example Online

16.02.2017 / 20:38