tags:

views:

361

answers:

2

Hi,

How do you calculate trig functions like cos, sin, tan in the iPhone SDK?

i tried tan(45) but it returns wrong output? any help?

+6  A: 

Most math libraries use radians, not degrees.

kdgregory
+2  A: 

functions like cos, sin and tan are in the standard library and can be used by including math.h. You can get a good overview of these by typing 'man math' in a Terminal window on your Mac. More specific info can be read by typing 'man sin' for example. You will then see that sin() takes a radians arguments, not degrees. Search here on Stack Overflow if you don't know how to convert radians to degrees.

St3fan
Bingo. `man sin`: "The sin() function computes the sine of x (measured in radians)."
Stephen Canon