操纵从 iPhone 4 获得的陀螺仪/加速计值
我正在为我的大学开发一个项目,用于操纵从 iPhone 4 获得的陀螺仪/加速度计值。但我遇到了一个数学问题,希望你们能帮助我。
我给你举个例子:
- 你的 iPhone 正面朝上,你将它在 Y 轴上向上移动。
- 你的 iPhone 正面朝右,你将它向上移动,这次是在 X 轴上(因为你将 iPhone 旋转了 90 度)。
第二次,计算机解释为我已将 iPhone 移至右侧,但这是错误的。我已经将其向上移动,但由于 iPhone 面朝右,所以我的轴发生了旋转。
我需要什么? 我需要一种方法将 iPhone 正面朝上(其中 3 轴是正确的)并为每个轴提供正确的移动值。
如果iPhone旋转90度,那么我可以轻松切换XZ轴及其正确性。但我想让它适用于任何旋转角度。
如果有人能帮助我提供某种伪算法或数学描述来做什么,我将非常感激。
注意:我只需要一种方法来根据 iPhone 旋转补偿所有三个轴。
更新:
我实际上不需要精确的值,因为我正在从陀螺仪获得的所有记录之间进行图形比较。我会说得更清楚。
->您只需将 iPhone 在空中移动即可画出一个字母,我的应用程序就会识别您刚刚画出的字母。我用于识别的方法是基于TFT算法,并将来自我之前绘制的字母的样本值记录到数据库中。
我的观点是:我得到的值或它们代表什么并不重要。我所需要的只是所有图表都相同,即使 iPhone 处于不同的位置。很难解释,但是如果你在 iPhone 向上转动的情况下绘制字母“P”,如果你在 iPhone 向右转动的情况下绘制“P”,则生成的图表将会有所不同。
所以我需要将轴补偿到原来的方向,这样我就会得到相似的图表。
I'm developing a project for my university, to manipulate gyroscope/accelerometer values obtained from the iPhone 4. But i'm stuck with a mathmatical issue and I hope you guys can help me out.
I'll give you an example of what's about:
- Your iPhone is face up and you move it UP, on Y axis.
- Your iPhone is face right and you move it UP, on X axis this time (since you rotated the iphone 90 degrees).
On the second time, the computer interprets that i've moved the iphone to the RIGHT, but it's wrong. I've moved it up, but my axis were rotated since the iphone was face right.
What do I need?
I need a way to VIRTUALY position back the iphone face up (where the 3 axis are correct) and give each axis his correct movement value.
If the iphone is turned 90 degrees, then I can easily switch X-Z axis and its correct. But I want to make it work for any angle of rotation.
I would be really thankfull if anyone can help me with some sort of pseudo-algorithm or mathmatical description of what to do.
NOTE: I only need a way to compensate all three axis acording with the iPhone rotation.
Update:
I don't actually need the precise values, since I'm making a graph coparition between all the records I get from the gyroscope. I'll make it clearer.
-> You draw a LETTER just by moving the iphone in the air and my application will recognize the letter you just drew. The method I use for recognition is based on TFT algorithm, and recording to a database with sample values originated from letters I've previously drawed.
My point is: Don't really matter the values I get, or what they represent. All I need is that all graphs be equal even if the iPhone is on different position. Quite hard to explain, but if you draw the letter 'P' with the iphone turned UP, the graph originated will be different if you draw the 'P' with the iPhone turned RIGHT.
So I need to compensate the axis to their original orientation, that way I'll get always similar graphs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这篇文章是在 iOS5 发布之前。仅供来到这里的任何人参考,DeviceMotion 相对于世界 -multiplyByInverseOfAttitude 展示了如何将设备相对加速度值转换为相对于地球的加速度值iOS5及以上版本。
This post was before iOS5 was released. FYI to anyone coming here, DeviceMotion relative to world - multiplyByInverseOfAttitude shows how to transform device-relative acceleration values to earth-relative for iOS5 and above.
因此,您想要的是将 iPhone 的坐标系(或对象/切线系统)转换为世界坐标系(反之亦然,如您所见,并不重要)。您了解 iPhone 坐标系就像了解陀螺仪数据一样。所以你想要的是创建对象->世界变换矩阵,并将每个速度向量(来自加速度计)乘以它。
请查看此处,了解切线空间的详细说明以及如何创建切线空间 ->世界变换矩阵。如果您不熟悉 3D/线性数学,这可能会有点棘手,但值得麻烦。
So, what you want is to convert from iPhone's coordinate system (or object/tangent system) to world coordinate system (or vice versa, as you see it, doesn't matter). You know the iPhone coordinate system as you have gyroscope data. So what you want is to create the object->world transformation matrix and multiple each of the velocity vectors (from accelerometer) by it.
Take a look here for a good explanation of tangent space and how to create tangent space -> world transformation matrix. If you aren't familiar with 3D/linear math it might be a bit tricky, but worth the trouble.