iphone - 核心动作(相对旋转) [英] iphone - core motion (relative rotation)

查看:112
本文介绍了iphone - 核心动作(相对旋转)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从核心运动中获得相对旋转?

Is there a way to obtain a relative rotation from core motion?

我需要的是:它在一个轴上旋转多少以及在哪个方向旋转(+符号=逆时针, - =顺时针,根据右手规则。)

What I need is: how much it rotated in one axis and which direction (+ sign = anti-clockwise, - = clockwise, according to the right-hand rule).

我找到了属性rotationRate,但我现在确定如何提取角度在它之外,因为这给了我每秒弧度。

I have found the property rotationRate, but I am now sure how I would extract the angle out of it, as this is giving me radians per second.

我在最后几天做过各种各样的事情,但没有什么能给我稳定的价值。我曾尝试使用NSTimer进行核心运动数据的定时采样,并计算两个样本之间的差异,因此我会调整自上次采样以来旋转了多少,但有时会给我疯狂的数字,如13600度即使iPhone搁在桌子上也是如此。

I have done all kind of stuff on the last days but nothing is giving me stable values. I have tried to do a timed sample of core motion data, using a NSTimer and calculate the difference between two samples, so I would have how much it rotated since the last sample, but from times to times it gives me crazy numbers like 13600 degrees even when the iPhone is resting on the table.

有关如何实现这一目标的任何想法?

Any thoughts on how this can be accomplished?

谢谢

推荐答案

确实如此。通过深入了解 CMMotionManager ,通过 CMDeviceMotion ,最后到 CMAttitude 。设备的态度定义为:

There is indeed. You can get what you're looking for by drilling down into the properties of CMMotionManager, through CMDeviceMotion and finally to CMAttitude. The attitude of the device is defined as:


给定参照系的身体相对于
a的方向。

the orientation of a body relative to a given frame of reference.

对于DeviceMotion的CMAttitude,该框架在启动设备运动更新时由框架建立。从那个时间点开始,相对于该参考帧(不是相对于前一帧)报告设备的态度。

In the case of DeviceMotion's CMAttitude, that frame of reference is established by the framework when starting device motion updates. From that point in time on, the attitude of the device is reported relative to that reference frame (not relative to the previous frame).

CMAttitude类提供了一些方便的构建在功能上将CMAttitude转换为实际上对某些内容有用的形式,例如Euler Angles,旋转矩阵或四元数。你听起来像是在寻找欧拉角表示(俯仰,偏航,滚动)。

The CMAttitude class provides some handy built in functionality to convert a CMAttitude to a form that is actually useful for something, like Euler Angles, a rotation matrix, or a quaternion. You sound like you're looking for the Euler Angle representation (Pitch, Yaw, Roll).

这篇关于iphone - 核心动作(相对旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆