我应该使用加速度计还是陀螺仪来测量z轴的角度 [英] Should i use Accelerometer or Gyroscope to measure angle of the z-axis

查看:781
本文介绍了我应该使用加速度计还是陀螺仪来测量z轴的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Android编写一个应用,该应用需要知道后置摄像头相对于地平线而不是相对于其最后位置的指向角度。我已经阅读了指南针和加速度计的所有定义,但并不是说我可以做到。

I am writing an An app in Android that needs to know the angle the rear camera is pointing with respect to the horizon and not with respect to it's last position. All of the definitions i have read for the compass and accelerometer don't say that i can do this. Is it at all possible to do this ?

推荐答案

您应该使用加速度计。

在静态照相机中,作用在照相机上的唯一力(由加速度计看到)是重力。这应该能够为您提供哪个方向是向下。然后,您需要做的是计算摄像机所面对的方向(该常数是常数,取决于加速度计的定向方式)与重力方向之间的角度。

The idea is the following, in a static camera, the only force (which is seen by the accelerometer) acting on the camera is gravity. This should be able to give you which direction is "down". What you would then need to do, is calculate the angle between the direction the camera is facing, (which is a constant, depending on which way your accelerometer is oriented) and the direction of gravity.

点积( http://en.wikipedia.org/wiki/Dot_product)中的两个向量应该给你向量的余弦(如果两个向量是单位向量),那么使用arccos可以得到弧度角。

The dot product (http://en.wikipedia.org/wiki/Dot_product) of the two vectors should give you the cosine of the vector (if the two vectors are unit vectors), then using arccos you should be able to get the angle in radians.

由于定义为(true)地平线是向下的90º(pi / 2以弧度为单位),因此应从点积的结果中减去pi / 2,结果应在-pi / 2和+ pi之间/ 2。

Since by definition, (true) horizon is 90º (pi/2 in radians) from down, you should subtract pi/2 from the result of the dot product, the result should be between -pi/2 and +pi/2.

-x的结果表示相机面向下并与水平线成x角。
+ x的结果表示相机面向上并与地平线成x角。

A result of -x means the camera is facing "down" and making an angle of x with the horizon. A result of +x means the camera is facing "up" and making an angle of x with the horizon.

这篇关于我应该使用加速度计还是陀螺仪来测量z轴的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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