提取偏航,俯仰和从rotationMatrix辊偏航、rotationMatrix

由网友(笙北)分享简介:我有一个传感器管理器,它返回一个 rotationMatrix 基于设备磁力仪和加速度计。我一直在努力也算对用户设备的偏航俯仰和滚转,但我发现,俯仰和横滚相互干扰,并给出不准确的结果。有没有一种方法来提取偏航变桨和从设备的ROLL的 rotationMatrix ?修改尝试以下除preT搅拌机的回答,我很感谢,但还没...

我有一个传感器管理器,它返回一个 rotationMatrix 基于设备磁力仪和加速度计。我一直在努力也算对用户设备的偏航俯仰和滚转,但我发现,俯仰和横滚相互干扰,并给出不准确的结果。有没有一种方法来提取偏航变桨和从设备的ROLL的 rotationMatrix

修改 尝试以下除preT搅拌机的回答,我很感谢,但还没有应用,我试图从一个rotaion矩阵这样的角度:

 浮动 -  [R [] = phoneOri.getMatrix();
       双rmYaw = Math.atan2(R [4],R [0]);
       双rmPitch = Math.acos(-R [8]);
       双rmRoll = Math.atan2(R [9]中,R [10]);
 

我不知道我是否引用矩阵或没有错误的部分,但我没有得到的结果,我觉得。

我希望得到的度值,但我越来越怪异的整数。

我的基质是来自我的的SensorManager 这看起来是这样的:

 公共无效onSensorChanged(SensorEvent EVT){
            整型= evt.sensor.getType();
            如果(类型== Sensor.TYPE_ORIENTATION){
                偏航= evt.values​​ [0];
                节距= evt.values​​ [1];
                辊= evt.values​​ [2];
            }
            如果(类型== Sensor.TYPE_MAGNETIC_FIELD){
                取向[0] =(取向[0] * 1 + evt.values​​ [0])* 0.5F;
                取向[1] =(取向[1] * 1 + evt.values​​ [1])* 0.5F;
                取向[2] =(取向[2] * 1 + evt.values​​ [2])* 0.5F;
            }否则,如果(类型== Sensor.TYPE_ACCELEROMETER){
                加速度[0] =(加速度[0] * 2 + evt.values​​ [0])* 0.33334f;
                加速度[1] =(加速度[1] * 2 + evt.values​​ [1])* 0.33334f;
                加速度[2] =(加速度[2] * 2 + evt.values​​ [2])* 0.33334f;
            }
            如果((类型== Sensor.TYPE_MAGNETIC_FIELD)||(类型== Sensor.TYPE_ACCELEROMETER)){
                浮newMat [] =新的浮动[16];

                SensorManager.getRotationMatrix(newMat,空,加速,定向);
                如果(displayOri == 0 || displayOri == 2){
                    SensorManager.remapCoordinateSystem(newMat,SensorManager.AXIS_X * -1,SensorManager.AXIS_MINUS_Y * -1,newMat);
                }其他{
                    SensorManager.remapCoordinateSystem(newMat,SensorManager.AXIS_Y,SensorManager.AXIS_MINUS_X,newMat);
                }

                矩阵= newMat;
 
二维平面旋转矩阵 RotationMatrix2D

当设备被放置面朝上表中的样品基质

  0.9916188,-0.12448014,-0.03459576,0.0
0.12525482,0.9918981,0.021199778,0.0
0.031676512,-0.02535538​​2,0.9991765,0.0
0.0,0.0,0.0,1
 

答案

 双rmPitch = Math.toDegrees(Math.acos(R [10]));
 

解决方案

偏航,俯仰和横滚对应欧拉角。您可以convert转换矩阵欧拉角 pretty的轻松:

I have a sensor manager that returns a rotationMatrix based on the devices Magnetometer and Accelerometer. I have been trying to also calculate the yaw pitch and roll of the user's device but am finding that pitch and roll interfere with each other and give inaccurate results. Is there a way to extract YAW PITCH and ROLL of a device from the rotationMatrix?

EDIT Trying to interpret blender's answer below, which i am thankful for but not quite there yet, i am trying to get the angle from a rotaion matrix like this:

       float R[] = phoneOri.getMatrix();
       double rmYaw = Math.atan2(R[4], R[0]);
       double rmPitch = Math.acos(-R[8]);
       double rmRoll = Math.atan2(R[9], R[10]);

i don't know if i am referencing the wrong parts of the matrix or not but i am not getting the results i would think.

i was hoping to get values in degrees, but am getting weird integers.

my matrix is coming from my sensorManager which looks like this:

public void onSensorChanged(SensorEvent evt) {
            int type=evt.sensor.getType();
            if(type == Sensor.TYPE_ORIENTATION){
                yaw = evt.values[0];
                pitch = evt.values[1];
                roll = evt.values[2];
            }
            if (type == Sensor.TYPE_MAGNETIC_FIELD) {
                orientation[0]=(orientation[0]*1+evt.values[0])*0.5f;
                orientation[1]=(orientation[1]*1+evt.values[1])*0.5f;
                orientation[2]=(orientation[2]*1+evt.values[2])*0.5f;
            } else if (type == Sensor.TYPE_ACCELEROMETER) {
                acceleration[0]=(acceleration[0]*2+evt.values[0])*0.33334f;
                acceleration[1]=(acceleration[1]*2+evt.values[1])*0.33334f;
                acceleration[2]=(acceleration[2]*2+evt.values[2])*0.33334f;
            }
            if ((type==Sensor.TYPE_MAGNETIC_FIELD) || (type==Sensor.TYPE_ACCELEROMETER)) {
                float newMat[]=new float[16];

                SensorManager.getRotationMatrix(newMat, null, acceleration, orientation);
                if(displayOri==0||displayOri==2){
                    SensorManager.remapCoordinateSystem(newMat,SensorManager.AXIS_X*-1, SensorManager.AXIS_MINUS_Y*-1,newMat);
                }else{
                    SensorManager.remapCoordinateSystem(newMat,SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,newMat);
                }

                matrix=newMat;

sample matrix when device is laying face up on table

0.9916188,  -0.12448014, -0.03459576,  0.0
0.12525482,  0.9918981,   0.021199778, 0.0
0.031676512,-0.025355382, 0.9991765,   0.0
0.0,         0.0,         0.0,         1

ANSWER

double rmPitch = Math.toDegrees( Math.acos(R[10]));

解决方案

Yaw, pitch and roll correspond to Euler angles. You can convert a transformation matrix to Euler angles pretty easily:

阅读全文

相关推荐

最新文章