旋转矢量传感器的使用

use of rotation vector sensor

我想实现旋转矢量传感器。我尽可能多地搜索了这个传感器,但我混淆了一些要点。我知道我需要使用 quaternions 而不是 Euler 角度来使我的应用程序更稳定。我将使用此传感器数据进行手势识别。所以我想使用 quaternions 但我不明白如何在使用 remapCoordinateSystem[=21 后将它们转换为 quaternions =] 方法?还是我想做的事情错了?即使是一点点帮助对我来说也是非常有用的。

@Override
public void onSensorChanged(SensorEvent event) {

    float[] rotationMatrix = new float[9];
    SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);

    float[] adjustedRotationMatrix = new float[9];
    SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, adjustedRotationMatrix);

    float[] orientation = new float[3];
    SensorManager.getOrientation(adjustedRotationMatrix, orientation);
    float pitch = orientation[1];
    float roll = orientation[2];
    float yaw = orientation[0];

    yawTextView.setText(getResources().getString(
            R.string.yaw_sensor,yaw));
    pitchTextView.setText(getResources().getString(
            R.string.pitch_sensor,pitch));
    rollTextView.setText(getResources().getString(
            R.string.roll_sensor,roll));

}

谢谢。

参见Euler angles to quaternion conversion

否则,如果您想直接从旋转矩阵计算四元数分量,请参阅 this page