计算相对方向给出方位,俯仰和横滚在Android的? [英] Compute relative orientation given azimuth, pitch, and roll in android?

查看:823
本文介绍了计算相对方向给出方位,俯仰和横滚在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我听定向事件在一个Android应用程序,我得到一个SensorEvent,其中包含3花车 - 方位角,俯仰和横滚相对于现实世界的轴。

When I listen to orientation event in an android app, I get a SensorEvent, which contains 3 floats - azimuth, pitch, and roll in relation to the real-world's axis.

现在说我建立像迷宫的应用程序,但我不希望强迫用户可以通过电话和拿着手机,使得XY平面平行于地面。相反,我希望能够让用户将手机作为他们希望,躺下或者,也许,坐下来拿着手机在一个角度。换句话说,我需要校准电话按照用户的preference

Now say I am building an app like labyrinth, but I don't want to force the user the be over the phone and hold the phone such that the xy plane is parallel to the ground. Instead I want to be able to allow the user to hold the phone as they wish, laying down or, perhaps, sitting down and holding the phone at an angle. In other words, I need to calibrate the phone in accordance with the user's preference.

我怎么能这样做?

另外请注意,我相信我的答案,是因为有 getRotationMatrix getOrientation ,但我不知道如何!

Also note that I believe that my answer has to do with getRotationMatrix and getOrientation, but I am not sure how!

请帮忙!我一直停留在这几个小时了。

Please help! I've been stuck at this for hours.

推荐答案

对于一个迷宫式的应用程序,你可能更关心的加速度(重力)比矢量轴方向。该载体,在电话的坐标系,是由三个加速度计测量的结合,而不是旋转角给出。具体而言,只有在 X 读数应影响球的运动。

For a Labyrinth style app, you probably care more for the acceleration (gravity) vector than the axes orientation. This vector, in Phone coordinate system, is given by the combination of the three accelerometers measurements, rather than the rotation angles. Specifically, only the x and y readings should affect the ball's motion.

如果你确实需要的方向,然后将3角读数重新present 3个欧拉角。不过,我怀疑你可能并不真正需要的角度本身,而是旋转矩阵的研究,这是由 getRotationMatrix() API返回。一旦你有了这个矩阵,那么它的基本上是你正在寻找的校准。当你想改变一个矢量在世界坐标到设备坐标,您应该由乘以逆的这个矩阵(其中,在这种特殊情况下,INV(研究) =转(研究)。

If you do actually need the orientation, then the 3 angular readings represent the 3 Euler angles. However, I suspect you probably don't really need the angles themselves, but rather the rotation matrix R, which is returned by the getRotationMatrix() API. Once you have this matrix, then it is basically the calibration that you are looking for. When you want to transform a vector in world coordinates to your device coordinates, you should multiply it by the inverse of this matrix (where in this special case, inv(R) = transpose(R).

所以,下面我找到了文档中的例子,如果你想改变世界重力矢量的先按g 的([​​0 0 G])到设备坐标,由INV乘以(<强>研究):

So, following the example I found in the documentation, if you want to transform the world gravity vector g ([0 0 g]) to the device coordinates, multiply it by inv(R):

= INV(研究)* 先按g

g = inv(R) * g

(注意,这应该给你同样的结果读取加速度计)

(note that this should give you the same result as reading the accelerometers)

可能的API在这里使用: invertM() multiplyMV()矩阵类的方法

Possible APIs to use here: invertM() and multiplyMV() methods of the matrix class.

这篇关于计算相对方向给出方位,俯仰和横滚在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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