Android SensorManager getOrientation getRotationMatrix
来源:互联网 发布:勒索软件的危害 编辑:程序博客网 时间:2024/05/17 01:35
大家都知道Type_Orientation传感器已被遗弃,由加速度传感器和磁传感器借助一定的算法虚拟出方向来,利用SensorManager.getOrientation获取,其中一个参数就是R[]。这需要我们知道getRotationMatrix()方法。
getRotationMatrix()方法说明中,定义的世界坐标系如下:
<img src="http://img.blog.csdn.net/20150802193335722" alt="" />
X轴平行于地面,指向东方。Y轴平行于地面,指向北极方向。Z轴垂直于地面,指向天空。
public static boolean getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic) { // TODO: move this to native code for efficiency float Ax = gravity[0]; float Ay = gravity[1]; float Az = gravity[2]; final float Ex = geomagnetic[0]; final float Ey = geomagnetic[1]; final float Ez = geomagnetic[2]; float Hx = Ey*Az - Ez*Ay; float Hy = Ez*Ax - Ex*Az; float Hz = Ex*Ay - Ey*Ax; final float normH = (float)Math.sqrt(Hx*Hx + Hy*Hy + Hz*Hz); if (normH < 0.1f) { // device is close to free fall (or in space?), or close to // magnetic north pole. Typical values are > 100. return false; } final float invH = 1.0f / normH; Hx *= invH; Hy *= invH; Hz *= invH; final float invA = 1.0f / (float)Math.sqrt(Ax*Ax + Ay*Ay + Az*Az); Ax *= invA; Ay *= invA; Az *= invA; final float Mx = Ay*Hz - Az*Hy; final float My = Az*Hx - Ax*Hz; final float Mz = Ax*Hy - Ay*Hx; if (R != null) { if (R.length == 9) { R[0] = Hx; R[1] = Hy; R[2] = Hz; R[3] = Mx; R[4] = My; R[5] = Mz; R[6] = Ax; R[7] = Ay; R[8] = Az; } else if (R.length == 16) { R[0] = Hx; R[1] = Hy; R[2] = Hz; R[3] = 0; R[4] = Mx; R[5] = My; R[6] = Mz; R[7] = 0; R[8] = Ax; R[9] = Ay; R[10] = Az; R[11] = 0; R[12] = 0; R[13] = 0; R[14] = 0; R[15] = 1; } } if (I != null) { // compute the inclination matrix by projecting the geomagnetic // vector onto the Z (gravity) and X (horizontal component // of geomagnetic vector) axes. final float invE = 1.0f / (float)Math.sqrt(Ex*Ex + Ey*Ey + Ez*Ez); final float c = (Ex*Mx + Ey*My + Ez*Mz) * invE; final float s = (Ex*Ax + Ey*Ay + Ez*Az) * invE; if (I.length == 9) { I[0] = 1; I[1] = 0; I[2] = 0; I[3] = 0; I[4] = c; I[5] = s; I[6] = 0; I[7] =-s; I[8] = c; } else if (I.length == 16) { I[0] = 1; I[1] = 0; I[2] = 0; I[4] = 0; I[5] = c; I[6] = s; I[8] = 0; I[9] =-s; I[10]= c; I[3] = I[7] = I[11] = I[12] = I[13] = I[14] = 0; I[15] = 1; } } return true; }
1 0
- Android SensorManager getOrientation getRotationMatrix
- Android getRotationMatrix和getOrientation原理
- Android中SensorManager.getRotationMatrix函数:计算出旋转矩阵,
- 实现指南针的新方法SensorManager.getOrientation( )
- 安卓 方向传感器The field Sensor.TYPE_ORIENTATION is deprecated use SensorManager.getOrientation()instead介绍
- android SensorManager简要分析
- Android之传感器SensorManager
- Android:SensorManager 传感器
- Android SensorManager \ SensorEventListener
- Android SensorManager分析
- Android 重力感应SensorManager Demo
- Android 屏幕旋转 Sensor SensorManager
- Android学习篇章56-SensorManager 指南针
- android 利用sensormanager获取设备的方向
- 最新历史版本 :Android 重力感应SensorManager Demo (转)
- Android中如何检测重力感应变化:Sensor和SensorManager
- 关于Android开发中SensorManager频率设置的问题
- Android SensorManager unregisterListener 无效的原因及其解决方法
- POJ2456 Aggressive cows(对整数二分)
- Activity的launchMode和任务栈小结
- hdu 5328 Problem Killer
- 我对说话人识别/声纹识别的研究综述
- just do it ,you will get more.
- Android SensorManager getOrientation getRotationMatrix
- Java虚拟机参数设置
- 71 独木舟上的旅行【贪心】
- MySql学习:索引
- 黑马程序员---iOS基础---Foundation框架
- L-BFGS算法(有限内存BFGS算法)
- Linux中rmdir和rm
- 双向链表的实现---数据结构学习(三)
- 乘法逆元的作用