首页 > 解决方案 > 如何获得android设备旋转

问题描述

我想在 x、y 和 z 轴上进行旋转 在此处输入图像描述

我想得到这些值

标签: android

解决方案


您可以通过以下方式获得 Azimuth、Pitch 和 Roll:

 private SensorManager sensorManager;
    ...
    // Rotation matrix based on current readings from accelerometer and magnetometer.
    final float[] rotationMatrix = new float[9];
    SensorManager.getRotationMatrix(rotationMatrix, null,
        accelerometerReading, magnetometerReading);

    // Express the updated rotation matrix as three orientation angles.
    final float[] orientationAngles = new float[3];
    SensorManager.getOrientation(rotationMatrix, orientationAngles);

来源https://developer.android.com/guide/topics/sensors/sensors_position#java


推荐阅读