小编use*_*127的帖子

从陀螺仪android传感器获取旋转度数

到目前为止,我已经在互联网上进行了薄弱的搜索。我正在尝试解决一个问题,我需要从手机起点开始的旋转度数。为了知道用户是否向上或向下移动手机,我使用了加速度计,它一开始有点不稳定,但我设法使其稳定。我现在需要围绕它自身旋转的角度。就像方向传感器一样,它已被弃用。然后我尝试使用磁力计,但我很不稳定。然后,当我使用示例代码时,我确定我想尝试使用陀螺仪:

 // This timestep's delta rotation to be multiplied by the current rotation
 // after computing it from the gyro sample data.
 if (timestamp != 0) {
     final float dT = (event.timestamp - timestamp) * NS2S;
     // Axis of the rotation sample, not normalized yet.
     float axisX = event.values[0];
     float axisY = event.values[1];
     float axisZ = event.values[2];

     // Calculate the angular speed of the sample
     float omegaMagnitude = (float) Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);

     // Normalize the rotation vector if …
Run Code Online (Sandbox Code Playgroud)

android gyroscope android-sensors

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-sensors ×1

gyroscope ×1