通过音高校正找到手机的方向

时间:2014-07-10 16:07:11

标签: android android-orientation

我需要制作一个应用来查找手机的方向。 我要测试的一些用例是

  • 手机在阅读位置(保持平稳)的使用时间
  • 用于拨打电话的时间(垂直)。
  • 多少时间放在口袋里。

我认为我应该能够从方向传感器中获得所有这些。 我在这里需要提一下,我最近开始开发和开发,所以我希望解决方案假定来自传感器的原始数据,以便稍后可以在Matlab中处理。事实上,一位同事正在帮助我进行发展。

我使用了标准的方式。方法:1

if (SensorManager.getRotationMatrix(rotationMatrix, null, accelerationValues, geoMagnetValues)) {

            SensorManager.getOrientation(rotationMatrix, orientation);

在-pi到pi的范围内滚动和方位角都可以,但是Android Compass that can Compensate for Tilt and Pitch中指向的距离在-pi / 2到pi / 2的范围内,我遇到了问题。所以我碰到了Android Compass that can Compensate for Tilt and Pitch的代码。 我刚刚使用它没有屏幕旋转调整。 我有几个问题。 Android Compass that can Compensate for Tilt and Pitch中定义的音高与我通过方法得到的音高不同:1当我向右倾斜电话时音高值发生变化而不应该改变。实际上它对应于方法1的滚动值。但是,当我通过Android Compass that can Compensate for Tilt and Pitch中的方法向我的手机转动音高时,给出了滚动值,但是具有不同的符号。 方位是好的。 最后m_pitch_axis_radians我完全无法理解。我知道我在解释这个不同的坐标系时遇到了一些问题,但如果我能得到一个关于方法:1中的俯仰,滚动和方位角如何与Android Compass that can Compensate for Tilt and Pitch中的方法相关的提示我会感激不尽

1 个答案:

答案 0 :(得分:1)

如果您想到飞机,则俯仰是飞机机头高于或低于水平的角度。所以看下面的图片,取决于你是在肖像还是风景中取决于"鼻子"是长边还是短边。因此,取决于设备的方向(即纵向与横向),俯仰和滚动的定义可以切换。

phone with axes labelled

关于m_pitch_axis_radians,Android Compass that can Compensate for Tilt and Pitch中的代码使用的坐标系由方位角,俯仰和俯仰轴定义,而不是标准方位角,俯仰和滚转。我建议你学习相应的数学文章What's the best 3D angular co-ordinate system for working with smartphone apps