【问题标题】:How to calculate and get the smooth value for pitch?如何计算并获得音高的平滑值?
【发布时间】:2016-09-29 08:31:36
【问题描述】:

我正在尝试找到一个准确的角度 (a),如下图所示。

通过研究,我了解到我可以使用 CMotionManger 获得角度。我创建了一个单例类,它将为我提供有关设备移动的更新。并使用 CMQuaternion

获得“Pitch”值

为了更好地理解什么是“Pitch”相对于轴,请参考下图。

这是我得到期望值的代码。这是找到第一张图片中显示的角度的正确方法吗?

- (void) startMotionUpdate {

if (self.motionManager == nil) {
    self.motionManager = [[CMMotionManager alloc] init];
}

self.motionManager.deviceMotionUpdateInterval = kUpdateInterval;

[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical
                                                        toQueue:self.deviceQueue
                                                    withHandler:^(CMDeviceMotion *motion, NSError *error)
{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        CGFloat x = motion.gravity.x;
        CGFloat y = motion.gravity.y;
        CGFloat z = motion.gravity.z;


        CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;
        double yaw = asin(2*(quat.x*quat.z - quat.w*quat.y));

        DLog(@"Yaw ==> %f", yaw);

        double myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z));

        DLog(@"myPitch ==> %.2f degree", myPitch);

        self.motionLastPitch = myPitch;
    }];
}];

}

在日志中我得到了这个打印:

    [Line 64] myPitch ==> 74.71 degree
 [Line 60] Yaw ==> -0.037314
 [Line 64] myPitch ==> 74.68 degree
 [Line 60] Yaw ==> -0.037849
 [Line 64] myPitch ==> 74.67 degree
 [Line 60] Yaw ==> -0.038531
 [Line 64] myPitch ==> 74.69 degree
 [Line 60] Yaw ==> -0.038637
 [Line 64] myPitch ==> 74.71 degree
 [Line 60] Yaw ==> -0.037314
 [Line 64] myPitch ==> 74.68 degree
 [Line 60] Yaw ==> -0.037849
 [Line 64] myPitch ==> 75.65 degree
 [Line 60] Yaw ==> -0.038531
 [Line 64] myPitch ==> 76.90 degree
 [Line 60] Yaw ==> -0.038637

我尝试按照第一张图片放置我的手机,那么这些值是否正确?如果是,那么如何获得 Pitch 的稳定值?

任何帮助/想法/指导都会有所帮助。

【问题讨论】:

    标签: ios objective-c iphone opengl-es core-motion


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 2019-09-23
    • 2018-06-28
    • 1970-01-01
    • 2021-06-01
    相关资源
    最近更新 更多