【问题标题】:use of rotation vector sensor使用旋转矢量传感器
【发布时间】:2021-08-12 07:10:00
【问题描述】:

我想实现旋转矢量传感器。我尽可能多地搜索了这个传感器,但我混淆了一些观点。我知道我需要使用 四元数 而不是 Euler 角度,以使我的应用程序更稳定。我将使用此传感器数据进行手势识别。所以我想使用 quaternions 但我不明白如何在使用 remapCoordinateSystem 方法后将它们转换为 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));

}

谢谢。

【问题讨论】:

    标签: android rotation android-sensors quaternions


    【解决方案1】:

    见Euler angles to quaternion conversion。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多