Question

For example,

  • sin 33.35 = 0.5523 in degree
  • sin 33.35 = 0.9347 in radian

As Xcode gives answers by default in radian. So is there any way to get answer in degree ???

Was it helpful?

Solution

Yes, you multiply radians by a constant, 180/pi, to get degrees. That's because there are 2 * pi radians in a complete circle of 360 degrees (so half a circle is pi radians and 180 degrees).

Just keep in mind that's a conversion you have to apply to the input of the sine function (the angle), not the output (which is a length).

The pi constant can be used by including math.h and using the M_PI symbol.

OTHER TIPS

A full circle in degrees exists of 360 degrees, and a full circle in radians is 2*pi. So, to convert radians to degrees, you divide by pi and multiply by 180.

radians * 180 / M_PI

If you would convert from degrees to radians, for example to provide degrees for a animation, use this:

degrees * M_PI / 180

I am using #DEFINEs for this myself:

#define DEGREES(radians)((radians)*180/M_PI)
#define RADIANS(degree)((degree)*M_PI/180)

Simply use by saying RADIANS(degree) or DEGREES(radians) in any part of your code, where you replace the degree and radians by the degree or radian value you had. This also keeps it more readable in my opinion if you are not used to radians.

Get the value in radians, then do:

CGFloat degrees = (radians * 180) / M_PI;

M_PI is a #define located in math.h.

Fortunately, the Objective-C language is a proper superset of C, which includes multiplication and division operators.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top