1. 程式人生 > >角度和弧度的轉換

角度和弧度的轉換

常用到如image1.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(335));

CGAffineTransformMakeRotation中要填的是弧度,所以要轉換一下。

下面是兩個巨集,來實現互轉

1。弧度轉角度
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))

NSLog(@”Output radians as degrees: %f”, RADIANS_TO_DEGREES(0.785398));

2。角度轉弧度
// Degrees to radians
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)

NSLog(@”Output degrees as radians: %f”, DEGREES_TO_RADIANS(45));
M_PI 定義在Math.h內,其值為3.14159265358979323846264338327950288