calculate acceleration in reference to true north

前端 未结 1 1966
时光取名叫无心
时光取名叫无心 2020-12-09 14:34

For my App I need to calculate the acceleration of my device in reference to true north. My idea was to calculate the device orientation to magnetic north and apply the decl

相关标签:
1条回答
  • 2020-12-09 15:09

    The accelerometer sensor returns the acceleration of the device. This is a vector in 3 dimentional space. This vector is returned in the device coordinate system. What you want is the coordinate of this vector in the world coordinate, which is simply

    R = rotation matrix obtained by calling getRotationMatrix
    A_D = accelerator vector return by sensor ( A_D = event.values.clone )
    A_W = R * A_D is the same acceleration vector in the world coordinate system.
    
    A_W is an array of dimention 3 
    A_W[0] is acceleration due east.
    A_W[1] is acceleration due north.
    

    Here is some code to compute it (assumes gravity and magnetic contain output from their respective sensors):

                float[] R = new float[9];
                float[] I = new float[9];
                SensorManager.getRotationMatrix(R, I, gravity, magnetic);
                float [] A_D = values.clone();
                float [] A_W = new float[3];
                A_W[0] = R[0] * A_D[0] + R[1] * A_D[1] + R[2] * A_D[2];
                A_W[1] = R[3] * A_D[0] + R[4] * A_D[1] + R[5] * A_D[2];
                A_W[2] = R[6] * A_D[0] + R[7] * A_D[1] + R[8] * A_D[2];
    
    0 讨论(0)
提交回复
热议问题