本文介绍了我应该如何计算方位角,俯仰方向的时候,我的Andr​​oid设备是不平坦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Android的重力和磁场传感器通过SensorManager.getRotationMatrix和SensorManager.getOrientation计算方向。这给我的方位,俯仰和方位的数字。结果看起来合理的设备时,平躺在桌子上。

I'm using the Android gravity and magnetic field sensors to calculate orientation via SensorManager.getRotationMatrix and SensorManager.getOrientation. This gives me the azimuth, pitch and orientation numbers. The results look sensible when the device is lying flat on a table.

不过,我有纵向和横向之间切换禁用清单中,让getWindowManager()。getDefaultDisplay()。getRotation()始终为零。当我旋转设备90度,所以,它的垂直放置我遇到了麻烦。有时这些数字显得相当错误的,我已经意识到这涉及到万向锁。但是,其他应用程序似乎不存在这个问题。举例来说,我比我对两个自由传感器测试的应用程序(传感器测试仪(Dicotomica)传感器监测(R的软件) )。我的应用程序同意这些应用程序时,该设备是平的,但我旋转设备到垂直位置可以有显著差异。这两个应用程序似乎都同意彼此,所以他们是如何解决这个问题得到什么呢?

However, I've disabled switches between portrait and landscape in the manifest, so that getWindowManager().getDefaultDisplay().getRotation() is always zero. When I rotate the device by 90 degrees so that it's standing vertical I run into trouble. Sometimes the numbers seem quite wrong, and I've realised that this relates to Gimbal lock. However, other apps don't seem to have this problem. For example, I've compared my app against two free sensor test apps (Sensor Tester (Dicotomica) and Sensor Monitoring (R's Software)). My app agrees with these apps when the device is flat, but as I rotate the device into the vertical position there can be significant differences. The two apps seem to agree with each other, so how do they get around this problem?

推荐答案

我想确定你的方向的最好办法角度时,该设备是不平坦是使用更合适的角度统筹制度,标准的欧拉角您从获得SensorManager.getOrientation(...)。我建议,我描述了一个here在math.stackexchange.com 。我也把一些code,它实现它的an回答这里。除了方位的一个很好的定义,它也有俯仰角的定义是完全Math.acos(rotationMatrix [8])中提到的由给出的角这里另一种答案。

I think the best way of defining your orientation angles when the device isn't flat is to use a more appropriate angular co-ordinate system that the standard Euler angles that you get from SensorManager.getOrientation(...). I suggest the one that I describe here on math.stackexchange.com. I've also put some code that does implements it in an answer here. Apart from a good definition of azimuth, it also has a definition of the pitch angle which is exactly the angle given by Math.acos(rotationMatrix[8]) that is mentioned in another answer here.

您可以从我在第一段所给出的两个环节全部细节。但是,总的来说,你的旋转矩阵研究从SensorManager.getRotationMatrix(...)为

You can get full details from the two links that I've given in the first paragraph. However, in summary, your rotation matrix R from SensorManager.getRotationMatrix(...) is

其中,(E X ,E 是,E 以Z ),(N X ,N 是,N 以Z )和(G X ,G 是,G 以Z )是向量指向正东,北,并在重力的方向。然后你想要的方位角是由

where (E, E, E), (N, N, N) and (G, G, G) are vectors pointing due East, North, and in the direction of Gravity. Then the azimuth angle that you want is given by

这篇关于我应该如何计算方位角,俯仰方向的时候,我的Andr​​oid设备是不平坦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:33