Someone asked me yesterday how can we convert the iphone accelerometer outputs to degrees. Well, it's easy. We are going to use the function
CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180/M_PI;};
and then, the only thing we need to do is
CGFloat angleXY=RadiansToDegrees(atan2(acceleration.y, acceleration.x));
For example, if we want to show this data in a UITextField called textXY
textXY.text=[NSString stringWithFormat:@"%f", angleXY];
Hope help!!
No comments:
Post a Comment