在iPhone中将UIAccelerometer数据转换为Degree?

时间:2012-09-03 07:57:38

标签: iphone uiaccelerometer degrees

任何想法如何将加速度计数据转换为度数?我开发了一个加速度计应用程序,我需要获得学位值?

  UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
     accel.delegate = self;
     accel.updateInterval = 1.0f/50.0f;

- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler 
    {

          NSLog(@"%f %f %f",aceler.x,aceler.y,aceler.z);

    }

我需要学位的价值吗?

1 个答案:

答案 0 :(得分:4)

X-Y角度的一个简单示例:

- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler 
{
   // get angle in radians
   float angle = atan2(aceler.x, aceler.y);
   // convert to degrees
   float angleInDegrees = (angle * 180/M_PI);
   NSLog(@"%f degrees",angleInDegrees); 
}