有没有办法获得来自核心运动的相对旋转?

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

我已经找到了属性轮流,但我现在确定我如何提取它的角度,因为这给了我每秒弧度。

我在最后几天完成了所有类型的东西,但没有什么是给我稳定的价值。我试图使用nstimer做一个定时的核心运动数据样本,并计算两个样本之间的差异,因此我会自上次样本以来旋转多少,但是从时代它给了我疯狂的数字,如13600度即使iPhone在桌子上休息。

对如何完成的任何想法?

感谢

有帮助吗?

解决方案

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:

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

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).

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).

其他提示

The answer provided above isn't quite accurate, though it's probably sufficient to answer this question. Core Motion tries to determine the device's absolute attitude at all times, meaning that the definition of the axes can vary depending on the device's orientation. For example, if the device is face-up, then pitch up/down is a rotation about the y-axis, but if the device is in landscape orientation, then pitch is a rotation about the z-axis (perpendicular to the plane of the screen). This is somewhat helpful if your application will only be used in one orientation, or you want a delta like the question asked for, but makes it excessively complicated if you want to know absolute orientation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top