【问题标题】:How to obtain quaternion from rotation matrix in Android?如何从Android中的旋转矩阵中获取四元数?
【发布时间】:2012-02-15 17:33:08
【问题描述】:

我正在尝试获取 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);

在“旋转”中,我有 4x4 旋转矩阵,在方向上,我有一个 float[3] 向量,其中有方位角、俯仰角和滚动角。

我现在怎样才能得到四元数?

【问题讨论】:

    标签: android android-sensors quaternions


    【解决方案1】:

    我不会使用欧拉角(滚动、俯仰、偏航),它几乎是您应用的 screws up the stability

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

    【讨论】:

    • 感谢您的回答。我想这就是我需要的。此外,解释它的谷歌视频非常清楚。再次感谢:)
    • @Alex 很高兴听到它。祝你好运!
    【解决方案2】:

    如果您不介意仅适用于 API 级别 9 及更高级别,您可以使用Sensor.TYPE_ROTATION_VECTOR,它无论如何都会返回一个单位四元数并为您节省工作量。如果输入一个长度为 3 的数组,值将是满足sin(theta / 2) * u 的四元数的向量部分,其中u 是一个 3D 单位向量。如果数组长度为 4,则第四个值将是单位四元数的标量值,cos(theta / 2)

    http://developer.android.com/reference/android/hardware/SensorEvent.html#values

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-28
      • 2010-12-06
      • 2019-02-10
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多