# How do I calculate the sine/cosine/tangent of an angle? Math.sin(angleInDegrees) doesn't seem to work.

John Zukowski

The trig functions in the Math class work in radians, not degrees. You need to convert the angle to radians before calling the appropriate method. Since 360 degrees = 2 pi radians, multiplying the angle by PI/180 will give you the appropriate value to pass along to the trig function. Starting with the 1.2 release of Java, you can also call Math.toRadians() and Math.toDegrees() to convert back and forth between the two units.

Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.