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

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

问题描述

在获取旋转矩阵值,它包含公共静态布尔getRotationMatrix(浮动[] R,漂浮[]我,漂浮[]重力,漂浮[]地磁) 在这里,我怎么能计算出浮法[]重力? 我发现,code在那里计算定位通过一个示例两个加速度磁场

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));
}

我的问题是:

My questions are :

  • 是定向值旋转矩阵值?
  • 如果没有那我怎么才能实现这个code,以获得旋转矩阵值采用磁?场?

要获取旋转矩阵我用这个code

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 是说取消定义为sensor.Any想法?

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 :

 =方位(弧度)

= azimuth (radians)

 =间距(弧度)

= pitch (radians)

 =卷(弧度)

= roll (radians)

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

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