tags:

views:

510

answers:

4

There is another post here about Atan but I dont see any relevant answers:

http://stackoverflow.com/questions/311501/c-why-math-atanmath-tanx-x

Isn't Math.Atan the same as tan-1? On my calculator I do:

tan-1(1) and i get 45.

tan(45) = 1

In C#:

Math.Atan(1) = 0.78539816339744828 // nowhere near the 45.

Math.Tan(45) = 1.6197751905438615 //1 dp over the < Piover2.

Whats happening here?

+3  A: 

Math.Atan returns a value in radians. Your calculator is using degrees. 0.7853... (pi/4) radians is 45 degrees. (And conversely Math.Tan(45) is telling you the tan of 45 radians.)

itowlson
+16  A: 

C# is treating the angles as radians; your calculator is using degrees.

Greg
+12  A: 
dlamblin
So ... Following how you use the words, shouldn't the methods be named DegreesToRadians() and RadiansToDegrees()?
unwind
Sure. Call them whatever you want. `d2r()` and `r2d()` might make fun macro names if C# supported macros.
dlamblin
+4  A: 

Your calculator is in Degrees, C# is doing these calculations in Radians.

To get the correct values:

int angle = 45;  //in degrees

int result = Math.Tan(45 * Math.PI/180);

int aTanResult = Math.Atan(result) *180/Math.PI;
Erich