iphone - 核心运动(相对旋转)
有没有办法从核心运动获得相对旋转?
我需要的是:它在一个轴上旋转了多少以及哪个方向(+号=逆时针,-=顺时针,根据右手定则)。
我找到了属性rotationRate,但我现在知道如何从中提取角度,因为这给了我每秒的弧度。
在过去的几天里我做了各种各样的事情,但没有什么能给我稳定的价值观。我尝试使用 NSTimer 对核心运动数据进行定时采样,并计算两个样本之间的差异,这样我就会知道自上次采样以来它旋转了多少,但有时它会给我疯狂的数字,例如 13600 度即使 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).
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.
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?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实有。您可以通过深入了解 CMMotionManager,通过 CMDeviceMotion 最后到 CMAttitude。设备的姿态定义为:
对于 DeviceMotion 的 CMAttitude,该参考系是在启动设备运动更新时由框架建立的。从该时间点开始,设备的姿态将相对于该参考系(而不是相对于前一帧)进行报告。
CMAttitude 类提供了一些方便的内置功能,可将 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:
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).
上面提供的答案不太准确,尽管它可能足以回答这个问题。 Core Motion 始终尝试确定设备的绝对姿态,这意味着轴的定义可能会根据设备的方向而变化。例如,如果设备面朝上,则向上/向下俯仰是绕 y 轴的旋转,但如果设备处于横向方向,则俯仰是绕 z 轴(垂直于平面)的旋转。屏幕)。如果您的应用程序仅在一个方向上使用,或者您想要一个像所要求的问题那样的增量,那么这会有所帮助,但如果您想知道绝对方向,则会变得过于复杂。
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.