使用磁场计算旋转矩阵 [英] Compute rotation matrix using the magnetic field

查看:26
本文介绍了使用磁场计算旋转矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在获取旋转矩阵值中它包含 public static boolean getRotationMatrix (float[] R, float[] I, float[] Gravity, float[] geomagnetic)这里我如何计算 float[] 重力?我找到了一个代码示例,它使用 AccelerometerMagnetic field

In get rotation matrix value it contains public static boolean getRotationMatrix (float[] R, float[] I, float[] gravity, float[] geomagnetic) Here how can i calculate the float[] gravity? I found a sample of code where it calculate the orientation using both Accelerometer and Magnetic 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));
}

我的问题是:

  • 方向值是旋转矩阵值吗?
  • 如果没有,那么我如何实现此代码以使用磁性获取旋转矩阵值?领域?

为了得到旋转矩阵,我使用这个代码

To get the rotation matrix i use this code

 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 说未定义传感器.知道吗?

But the problem is this getRotationMatrixFromVector is says undefine for sensor.Any idea?

推荐答案

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

Orientation is not a rotation matrix as it only provides you angles related to magnetic North. You can obtain the rotation matrix (Direction Cosine Matrix) that will help you to transform coordinates from your device frame to the Earth's frame this way :

= 方位角(弧度)

= 间距(弧度)

= 滚动(弧度)

这篇关于使用磁场计算旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆