我正在使用Android 3.1设备中陀螺仪传感器的方向值旋转矩形。

我必须非常快速地旋转我的设备才能获得值1.0以上的值。

这是代码

final float currentRotVector[] = { 1, 0, 0, 0 };

if (timestamp != 0)

{

final float dT = (event.timestamp - timestamp) * NS2S;

// Axis of the rotation sample, not normalized yet.

// Calculate the angular speed of the sample

float omegaMagnitude = (float) Math.sqrt(X * X + Y * Y + Z * Z);

// Normalize the rotation vector if it's big enough to get the axis

if (omegaMagnitude > EPSILON)

{

X /= omegaMagnitude;

Y /= omegaMagnitude;

Z /= omegaMagnitude;

}

// Integrate around this axis with the angular speed by the timestep

// in order to get a delta rotation from this sample over the timestep

// We will convert this axis-angle representation of the delta rotation

// into a quaternion before turning it into the rotation matrix.

float thetaOverTwo = dT * omegaMagnitude / 2.0f;

float sinThetaOverTwo = (float) Math.sin(thetaOverTwo);

float cosThetaOverTwo = (float) Math.cos(thetaOverTwo);

deltaRotationVector[0] = cosThetaOverTwo;

deltaRotationVector[1] = sinThetaOverTwo * X;

deltaRotationVector[2] = sinThetaOverTwo * Y;

deltaRotationVector[3] = sinThetaOverTwo * Z;

/* quaternion multiplication

Reference: http://www.cprogramming.com/tutorial/3d/quaternions.html

*/

currentRotVector[0] = deltaRotationVector[0] * currentRotVector[0] -

deltaRotationVector[1] * currentRotVector[1] -

deltaRotationVector[2] * currentRotVector[2] -

deltaRotationVector[3] * currentRotVector[3];

currentRotVector[1] = deltaRotationVector[0] * currentRotVector[1] +

deltaRotationVector[1] * currentRotVector[0] +

deltaRotationVector[2] * currentRotVector[3] -

deltaRotationVector[3] * currentRotVector[2];

currentRotVector[2] = deltaRotationVector[0] * currentRotVector[2] -

deltaRotationVector[1] * currentRotVector[3] +

deltaRotationVector[2] * currentRotVector[0] +

deltaRotationVector[3] * currentRotVector[1];

currentRotVector[3] = deltaRotationVector[0] * currentRotVector[3] +

deltaRotationVector[1] * currentRotVector[2] -

deltaRotationVector[2] * currentRotVector[1] +

deltaRotationVector[3] * currentRotVector[0];

final float rad2deg = (float) (180.0f / Math.PI);

RotAngle = currentRotVector[0] * rad2deg;

axisX = currentRotVector[1];

axisY = currentRotVector[2];

axisZ = currentRotVector[3];

Log.i("Sensor Orientation GyroScope", "axisX: " + axisX + //

" axisY: " + axisY + //

" axisZ: " + axisZ + //

" RotAngle: " + RotAngle);

}timestamp = event.timestamp;

我得到了一些输出

axisX:0.69363713 axisY:0.18359372 axisZ:0.0228636 RotAngle:36.7191

并且由于轴的值,当设备放在桌子上时,输出矩形看起来会被调整。

上面的代码有问题吗?

android陀螺仪方向,Android中陀螺仪传感器正确旋转值的计算相关推荐

  1. 在Android的 设置-显示 中增加控制屏幕旋转方向的选项

    在Android的 设置->显示 中增加控制屏幕旋转方向的选项 参考博文 实现目标 效果局限 代码实现 配置资源文件 界面搭建 功能实现 默认值修改 其他情况 结语 参考博文 Android-x ...

  2. android pcm 音量_Android中实时获取音量分贝值详解

    基础知识 度量声音强度,大家最熟悉的单位就是分贝(decibel,缩写为dB).这是一个无纲量的相对单位,计算公式如下: 分子是测量值的声压,分母是参考值的声压(20微帕,人类所能听到的最小声压).因 ...

  3. android机器人方向,Android绘制机器人小实例

    本文实例通过前面学过的Paint.Canvas等2D绘画技术来实现在手机屏幕上绘制Android机器人. 具体代码实现和效果: 用来显示自定义的绘图类的布局文件 res/layout/main.xml ...

  4. android重新编译res,使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中lt;meta-datagt;变量的值...

    你也能够查看我的其它同类文章.也会让你有一定的收货 关于使用Gradle来控制版本号和生成不同版本号的代码.我总结了三篇文章,网上关于这些知识,都比較零散.我在学习这些的之前.根本不知道还有这种方法. ...

  5. 使用 gradle 在编译时动态设置 Android resValue / BuildConfig / Manifes中lt;meta-datagt;变量的值...

    转载请标明出处:http://blog.csdn.net/xx326664162/article/details/49247815 文章出自:薛瑄的博客 你也能够查看我的其它同类文章.也会让你有一定的 ...

  6. android 图片方向,Android图片处理:识别图像方向并显示

    在Android中使用ImageView显示图片的时候发现图片显示不正.方向偏了或者倒过来了. 解决问题非常自然想到的分两步走: 1.自己主动识别图像方向,计算旋转角度. 2.对图像进行旋转并显示. ...

  7. android 显示线方向,Android recycleview 分割线彩蛋

    我收集了一些学习用的资料,其中包含了很多学习,面试,中高进阶fluuter资料,还有很多视频详解,如果有同学想进一步了解,详情请看文末.也欢迎各路大神门前来装X. 首先上问题 怎么做? 当我们空余时间 ...

  8. android 摄像头方向,android:调整摄像头方向

    在代码中可直接调用该方法. 参数:activity 为当前上下文: cameraId 为摄像头的ID,及前置摄像头或后置摄像头的ID import android.hardware.Camera; C ...

  9. android lineargradient 方向,Android LinearGradient和奇怪的相对定位

    我有以下代码和LinearGradient,它与其他所有示例看起来非常相似. public class CustomColourBar extends View { public CustomColo ...

  10. android高德方向,Android 高德地图进阶功能

    本文接本人上一篇文章:Android APP接入高德SDK问题与记录,如果还不熟悉高德地图接入,可以先阅读这篇文章. 1 切换图层及显示路况 通过设置mapType,可以切换地图的类型: aMap.m ...

最新文章

  1. 4.9一个简单的多任务内核实例
  2. linux下压缩命令gzip使用
  3. Linux监控FastCGI程序自启,Linuxx下fastcgi安装
  4. 晋级赛关键一场遇到服务器中途维护,第四届全球争霸赛-大区赛常见问题说明...
  5. 第七届蓝桥杯省赛---蚂蚁感冒
  6. 将byte数组以html形式输出到页面,java 数组显示到html
  7. 数字图像处理,读懂频域处理的“傅里叶变换”
  8. leetcode —— 207. 课程表
  9. Easyui Datagrid的Rownumber行号显示问题
  10. [已破案] 镜像出问题了
  11. cass参考手册_CASS9.2参考手册
  12. c语言计算器程序设计,c语言计算器代码程序设计报告.docx
  13. html rgb 颜色转换,将RGBA颜色转换为HTML颜色代码
  14. (转)日期插件layDate的使用
  15. F - Endless Walk
  16. Vue打开外部链接问题
  17. 干货 | 相机标定:机器人手眼标定
  18. android webview崩溃,Android-未知的webview崩溃原因
  19. 微信公众平台服务号、订阅号的相关说明
  20. 上云安全建设之CDN安全防护

热门文章

  1. 苹果手机怎样双开微信?简单2步快速安装苹果版双开助手!
  2. 如何在jupyter notebook中设置一级二级三级标题?
  3. Python+旧衣物捐赠系统 毕业设计-附源码290942
  4. 木本坚果的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  5. 肿瘤 材料 计算机模拟,PeerJ: 计算机模拟揭示癌症多样性
  6. nas 和 远程文件夹同步_我应该如何使用Qsync来同步我计算机和NAS上的档案?
  7. 【IOS】iphone逻辑分辨率
  8. 各种文件的mime类型
  9. excel如何取消合并单元格并自动填充
  10. html中 DPlayer 播放m3u8文件【方式二】