问题描述
从我的 Android 设备中,我可以读取一组线性加速度值(在设备坐标系中)和一组绝对方向值(在地球坐标系中).我需要的是获得后一个坐标中的线性加速度值.系统.
From my Android device I can read an array of linear acceleration values (in the device's coordinate system) and an array of absolute orientation values (in Earth's coordinate system). What I need is to obtain the linear acceleration values in the latter coord. system.
如何转换它们?
EDIT 在阿里回复评论后:
好吧,所以如果我理解正确的话,当我测量线性加速度时,手机的位置完全无关紧要,因为读数是在地球坐标系中给出的.对吗?
All right, so if I understand correctly, when I measure the linear acceleration, the position of the phone completely does not matter, because the readings are given in Earth's coordinate system. right?
但我刚刚做了一个测试,我将手机放在不同的位置,并在不同的轴上获得加速度.有 3 对图片 - 第一张显示了我如何放置设备(对不起我的油漆大师技能"),第二张显示了线性加速度计提供的数据的读数.传感器:
But I just did a test where I put the phone in different positions and got acceleration in different axes. There are 3 pairs of pictures - the first ones show how I put the device (sorry for my Paint "master skill") and the second ones show readings from data provided by the linear acc. sensor:
- 设备放在左侧
- 设备仰卧
- 设备站立
现在 - 为什么在第三种情况下加速度沿 Z 轴(而不是 Y)发生,因为设备位置无关紧要?
And now - why in the third case the acceleration occurs along the Z axis (not Y) since the device position doesn't matter?
推荐答案
我终于解决了!因此,要在地球坐标系中获得加速度矢量,您需要:
I finally managed to solve it! So to get acceleration vector in Earth's coordinate system you need to:
- 从
SensorManager.getRotationMatrix()
获取旋转矩阵(float[16]
以便稍后由android.opengl.Matrix
类使用)code>(使用SENSOR.TYPE_GRAVITY
和SENSOR.TYPE_MAGNETIC_FIELD
传感器值作为参数), - 在旋转矩阵上使用
android.opengl.Matrix.invertM()
来反转它(不是转置!), - 使用
Sensor.TYPE_LINEAR_ACCELERATION
传感器获得线性加速度矢量(在设备的坐标系中), - 使用
android.opengl.Matrix.multiplyMV()
将旋转矩阵乘以线性加速度向量.
- get rotation matrix (
float[16]
so it could be used later byandroid.opengl.Matrix
class) fromSensorManager.getRotationMatrix()
(usingSENSOR.TYPE_GRAVITY
andSENSOR.TYPE_MAGNETIC_FIELD
sensors values as parameters), - use
android.opengl.Matrix.invertM()
on the rotation matrix to invert it (not transpose!), - use
Sensor.TYPE_LINEAR_ACCELERATION
sensor to get linear acceleration vector (in device's coord. sys.), - use
android.opengl.Matrix.multiplyMV()
to multiply the rotation matrix by linear acceleration vector.
这就给你了!我希望我能为他人节省一些宝贵的时间.
And there you have it! I hope I will save some precious time for others.
感谢 Edward Falk 和 Ali 的提示!!
Thanks for Edward Falk and Ali for hints!!
这篇关于从设备坐标系到绝对坐标系的加速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!