在获取旋转矩阵值中,它包含 public static boolean getRotationMatrix (float[] R, float[] I, float[] gravity, float[] geomagnetic) 在这里,我如何计算 float[] gravity?我发现了一个代码示例,它计算 orientation 同时使用两者 AccelerometerMagnetic field

boolean success = SensorManager.getRotationMatrix(
   matrixR,
   matrixI,
   valuesAccelerometer,
   valuesMagneticField);

if(success){
SensorManager.getOrientation(matrixR, matrixValues);

double azimuth = Math.toDegrees(matrixValues[0]);
double pitch = Math.toDegrees(matrixValues[1]);
double roll = Math.toDegrees(matrixValues[2]);

readingAzimuth.setText("Azimuth: " + String.valueOf(azimuth));
readingPitch.setText("Pitch: " + String.valueOf(pitch));
 readingRoll.setText("Roll: "+String.valueOf(roll));
}

我的问题是 :

  • 方位值是旋转矩阵值吗?
  • 如果没有,那么我怎样才能实现这个代码来获得使用磁性的旋转矩阵值?菲尔德?

要获得旋转矩阵,我使用以下代码

 public void onSensorChanged(SensorEvent sensorEvent) {
    if (timestamp != 0) {
        final double dT = (sensorEvent.timestamp - timestamp) * NS2S;
            double magneticX = sensorEvent.values[0];
            double magneticY = sensorEvent.values[1];
            double magneticZ = sensorEvent.values[2];
                        double omegaMagnitude =Math.sqrt(magneticX*magneticX + magneticY*magneticY + magneticZ*magneticZ);

                        if (omegaMagnitude > EPSILON) {
                            magneticX /= omegaMagnitude;
                            magneticY /= omegaMagnitude;
                            magneticZ /= omegaMagnitude;
        }
                        double thetaOverTwo = omegaMagnitude * dT / 2.0f;
                        double sinThetaOverTwo =Math.sin(thetaOverTwo);
                        double cosThetaOverTwo = Math.cos(thetaOverTwo);
                        deltaRotationVector[0] = (double) (sinThetaOverTwo * magneticX);
                        deltaRotationVector[1] = (double) (sinThetaOverTwo * magneticY);
                        deltaRotationVector[2] = (double) (sinThetaOverTwo * magneticZ);
                        deltaRotationVector[3] = cosThetaOverTwo;


    }
     double[] deltaRotationMatrix = new double[9];
     SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
}

但问题是 getRotationMatrixFromVector 对于传感器来说是不确定的。知道吗?

有帮助吗?

解决方案

方向不是旋转矩阵,因为它只提供与磁北相关的角度。您可以获得 旋转矩阵 (方向余弦矩阵),这将帮助您转换坐标从您的设备框架到地球的框架这种方式 :

DCM from Wikipedia

azimuth =方位角(弧度)

pitch =音高(弧度)

roll =卷(弧度)

其他提示

我知道这是一个旧的线程,但如果它有帮助,对于Android我认为3x3旋转矩阵实际上是由批准的答案的变体给出的。具体来说,在Android中,旋转矩阵是

     (cosφ cosψ - sinφ sinψ sinθ)     sinφ cosθ     ( cosφ sinψ + sinφ cosψ sinθ)
    -(sinφ cosψ + cosφ sinψ sinθ)     cosφ cosθ     (-sinφ sinψ + cosφ cosψ sinθ)
              -sinψ cosθ                 -sinθ                  cosφ cosθ

哪里

    φ = azimuth
    θ = pitch
    ψ = roll

其中对应于3x3的Android旋转矩阵R[0]到R[8](问题中的matrixR)通过

    R[0] R[1] R[2]
    R[3] R[4] R[5]
    R[6] R[7] R[8]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top