title: Transforming accelerometer's data from device's coordinates to real world coordinates
body: <p>I'm really sorry if this is a very basic question, but I have not choice but ask it: How do you translate the accelerometer data from the device coordinates to real world coordinates?</p>
  
  <p>I mean, assuming that the accelerometer is giving me somenting like (Ax,Ay,Az) -<a href="http://www.anddev.org/novice-tutorials-f8/acceleration-orientation-visual-reference-t11818.html">in device's coordinates</a>-, what transformations should I apply to transform the values into (Ax',Ay',Az') -<a href="http://developer.android.com/reference/android/hardware/SensorManager.html#getOrientation%28float%5B%5D,%20float%5B%5D%29">in real world's coordinates</a>-, so I can use the acceleration vector in real worlds coordinates to calculate if the device is accelerating north, east, south-west,etc?</p>
  
  <p>I have been working around this issue during the past few days. At first I thought that it shound't be difficult, but after searching dozens of pages I haven't come up with anything functional.</p>
  
  <p>By the way, here is some code with what I've implemented so far:</p>
  
  <pre><code>    private SensorEventListener mSensorEventListener = new SensorEventListener() {
  
      public void onAccuracyChanged(Sensor sensor, int accuracy){
  }
  
      public void onSensorChanged(SensorEvent event) {
          switch(event.sensor.getType()){
          case Sensor.TYPE_ACCELEROMETER:
              accelerometervalues = event.values.clone();
              AX.setText(accelerometervalues[0]+"");
              AY.setText(accelerometervalues[1]+"");
              AZ.setText(accelerometervalues[2]+"");
              break;
          case Sensor.TYPE_ORIENTATION:
              orientationvalues = event.values.clone();
              azimuth.setText(orientationvalues[0]+"");
              pitch.setText(orientationvalues[1]+"");
              roll.setText(orientationvalues[2]+"");
              break;
          case Sensor.TYPE_MAGNETIC_FIELD:
              geomagneticmatrix =event.values.clone();
              TAX.setText(geomagneticmatrix[0]+"");
              TAY.setText(geomagneticmatrix[1]+"");
              TAZ.setText(geomagneticmatrix[2]+"");
              break;
          }
          if (geomagneticmatrix != null &amp;&amp; accelerometervalues != null) {
              float[] R = new float[16];
              float[] I = new float[16];
              SensorManager.getRotationMatrix(R, I, accelerometervalues, geomagneticmatrix);
              //What should I do here to transform the components of accelerometervalues into real world acceleration components??
          }
     }
  };
  </code></pre>
  
  <p>I have:</p>
  
  <p>A vector of accelerations in native coordinates in <code>accelerometervalues</code>.</p>
  
  <p>A vector of magnetic field values in <code>geomagneticmatrix</code>.</p>
  
  <p>Azimuth, pitch and roll in <code>orientationvalues</code>.</p>
  
  <p>Rotation matrix <code>R</code>.
  Inclination matrix <code>I</code>.</p>
  
  <p>I think all the necessary information is there, azimuth, pitch and roll should describe the displacement of the device's coordinate system in relation with the real world coordinate system. Also, I believe that <code>R</code> is/can even be used as a true north vector inside the devices coordinates.</p>
  
  <p>It seems to me that obtaing the values of acceleration in real world is just a mathematical transformation away from those data. I just can't figure it out.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edited:</p>
  
  <p>I have tried directly multipliying the components of <code>accelerometervalues</code> with the rotation matrix <code>R</code> (trueaccel=accel*R) but it didn't work. </p>
  
  <pre><code>                    trueacceleration[0]= accelerometervalues[0]*R[0]+accelerometervalues[1]*R[1]+accelerometervalues[2]*R[2];
                  trueacceleration[1]= accelerometervalues[0]*R[1]+accelerometervalues[1]*R[4]+accelerometervalues[2]*R[7];
                  trueacceleration[2]= accelerometervalues[0]*R[2]+accelerometervalues[1]*R[5]+accelerometervalues[2]*R[8];
  </code></pre>
  
  <p>I have also tried multipliying <code>accelerometervalues</code> with the inclination matrix I. Also multipliying with both R and I (trueaccel=accel*R*I) and that didn't work either. Neither does calling to <code>remapcoordinates()</code> and then multiply in any of the previous forms.</p>
  
  <p>Does anybody have an idea about what am I doing wrong?</p>