而设备仍然停留在垂直轴上的Andr​​oid设备的角度 [英] Android device angle on vertical axis while device stays still

查看:165
本文介绍了而设备仍然停留在垂直轴上的Andr​​oid设备的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发展我的第一个应用程序,并进行一些计算,我需要垂直轴的角度。基本上我试图让简单的衡量工具,它会做的按钮点击计算。
我有高度(H),其中设备是我需要的设备垂直轴的角度。有了这些价值观我就可以计算出罪等。

I am developing my first app and for some calculations I need an angle of vertical axis. Basically I am trying to make simple measure tool which would do the calculations on Button click. I have height(H) in which is device and I need angle of device vertical axis. Having these values I'll be able to calculate sin and so on.

我试图用code从这个链接(<一个href=\"http://stackoverflow.com/questions/4020048/finding-orientation-using-getrotationmatrix-and-getorientation\">finding使用getRotationMatrix()和getOrientation()方向),以获得值,但是它崩溃,也是我认为这不是我想要的值,因为设备保持着静止。

I tried to use code from this link (finding orientation using getRotationMatrix() and getOrientation()) to get values, but it crashes and also I think it's not the values I want, because device stays still.

Iliustration我的意思(我有'H'的价值和我寻找角'一'或从中我可以提取它的数据):

Iliustration of what I mean (I have 'H' value and I am searching for angle 'a' or data from which I can extract it):

任何有用的链接,教程或样本将是非常有益的。

Any useful links, tutorials or samples would be very helpful.

推荐答案

我认为在Android设备将沿着你所绘制的三角形的斜边是在说谎,因此,如果该设备已在桌子上平躺着,然后您的角度A将是90度,并且如果该装置直立则角'一'将是零。如果是这样,那么该角度A是与该设备,而这正是你应该是什么能够通过使用getRotationMatrix()和getOrientation得到()的间距。然而,在球场通常被定义为为零时,该设备是平躺在桌子上时,它的直立90度,让您的角度A等于(90度 - 间距)。谨防单位,有时角度弧度,有时度。

I assume that the Android device will be lying along the hypotenuse of the triangle that you've drawn, so that if the device was lying flat on the table then your angle 'a' would be 90 degrees, and if the device is standing upright then the angle 'a' would be zero. If so, then that angle 'a' is related to the pitch of the device, which is exactly what you should be able to get by using getRotationMatrix() and getOrientation(). However, the pitch is usually defined as being zero when the device is lying flat on the table and 90 degrees when it's upright, so your angle 'a' is equal to (90 degrees - pitch). Beware of units, sometimes angles are in radians, and sometimes in degrees.

如果您code崩溃,那么你一定不小心引入了错误的地方,因为我肯定能够得到使用getRotationMatrix()和getOrientation()没有崩溃code。

If you code is crashing, then you must have accidentally introduced a bug somewhere, because I've certainly got code that uses getRotationMatrix() and getOrientation() without crashing.

您会发现,一些由getOrientation产生的取向值()变得不稳定,当装置接近垂直位置。这是锁的,被称为万向一个问题,因为当装置竖向,方位和滚是同一回事。然而,间距应保持可靠的。

You'll find that some of the orientation values produced by getOrientation() become erratic when the device approaches a vertical position. This is a problem known as Gimbal lock, because when the device is verical, azimuth and roll are the same thing. However, pitch should remain reliable.

如果你需要可靠的方位以及俯仰时,该设备是垂直的,那么你可以看看<一个href=\"http://stackoverflow.com/questions/16317599/android-compass-that-can-compensate-for-tilt-and-pitch/16386066#16386066\">my回答这个问题Android的指南针,可补偿倾斜和间距。这个问题的答案有code,它肯定工程,如果你不能得到getRotationMatrix()和getOrientation()的工作,然后散发出来的间距将正常工作适合你。

If you ever need reliable azimuth as well as pitch when the device is vertical, then you could have a look at my answer to the question 'Android Compass that can Compensate for Tilt and Pitch'. That answer has code that definitely works, and if you can't get getRotationMatrix() and getOrientation() working, then the pitch that comes out of that will work fine for you.

这篇关于而设备仍然停留在垂直轴上的Andr​​oid设备的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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