Android 在地球坐标系上获取加速度计 [英] Android get accelerometers on earth coordinate system

查看:41
本文介绍了Android 在地球坐标系上获取加速度计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Android 上获得加速度计并将它们放在地球坐标系上,就像在这个主题上一样 从设备坐标系到绝对坐标系的加速度 或这里将加速度计的数据从设备坐标转换为真实世界坐标,但这些解决方案对我不起作用.我正在处理.该项目只是跟踪手机在太空中的加速度,无论它如何(站立,侧面......).我也是安卓新手.我很感激你的帮助!谢谢你.

I'd like to get accelerometers on Android and have them on the earth coordinate system, just like on this topic Acceleration from device's coordinate system into absolute coordinate system or here Transforming accelerometer's data from device's coordinates to real world coordinates but these solutions don't work for me. I'm working on Processing. The project is simply to track the phones accelerations in space, no matter how it is (standing, on the side...). I'm new to Android too. I'd appreciate your help! Thank you.

我不需要手机的确切位置,只需要加速度.

Edit : I don't need the phones exact position, only accelerations.

推荐答案

我终于解决了!我结合了 2 个以前的答案,这是代码:

I finally worked it out! I combined 2 previous answers, here is the code :

  monSensorManager.getRotationMatrix(Rotate, I, gravity_values, mag_values); 
  float[] relativacc = new float[4];
  float[] inv = new float[16];
  relativacc[0]=lin_values[0];
  relativacc[1]=lin_values[1];
  relativacc[2]=lin_values[2];
  relativacc[3]=0;
  android.opengl.Matrix.invertM(inv, 0, Rotate, 0);
  android.opengl.Matrix.multiplyMV(earthAcc, 0, inv, 0, relativacc, 0);

1) 获取地球坐标中的手机单位向量2) 求逆矩阵以得到手机坐标中的地球单位向量3) 将手机加速度乘以单位向量,将手机坐标转换为地球坐标.谢谢大家的帮助!

1) Get phone unit vector in earth coordinates 2) Invert matrix to get earth unit vector in phone coordinates 3) Multiply phone acceleration by unit vector to transform phone coordinates to earth coordinates. Thank you all for your help!

这篇关于Android 在地球坐标系上获取加速度计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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