如何从Android中的旋转矩阵中获取四元数?

Ale*_*lex 2 android quaternions android-sensors

我正在尝试获取Android设备的方向,我需要它在四元数结构(float[4]基本上).

我现在拥有的是:

if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
    last_acc = (float[])event.values.clone();
}
else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD){
    last_mag = (float[])event.values.clone();
}
if (last_acc != null && last_mag != null){
    SensorManager.getRotationMatrix(rotation, inclination, last_acc, last_mag);
    SensorManager.getOrientation(rotation, orientation);
Run Code Online (Sandbox Code Playgroud)

在"旋转"中,我有4x4旋转矩阵,并且在方向上我有一个float [3]向量,其中我有方位角,俯仰和滚动.

我怎样才能得到四元数?

Ali*_*Ali 5

我不会使用欧拉角(滚动,俯仰,偏航),它几乎搞砸了你应用的稳定性.

至于将旋转矩阵转换为四元数,谷歌说: