使用磁场计算旋转矩阵(Compute rotation matrix using the magne

2019-07-29 11:36发布

在获取旋转矩阵值包含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是说取消定义为sensor.Any想法?

Answer 1:

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

=方位角(弧度)

=间距(弧度)

=辊(弧度)



Answer 2:

我知道这是一个古老的线程,但万一有帮助,为Android,我认为3×3的旋转矩阵实际上是由经批准的答案的变化给出。 具体而言,在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

这对应于3×3的Android旋转矩阵R [0]至R [8](matrixR中的问题),通过

    R[0] R[1] R[2]
    R[3] R[4] R[5]
    R[6] R[7] R[8]


文章来源: Compute rotation matrix using the magnetic field