2
  • Acceleration is tracked (X,Y,Z) in m/s^2 relative to the phone.
  • Orientation is tracked in Euler angles relative to "earth".

Can I use orientation to calculate acceleration relative to "earth"?

If yes, could you explain how to do it?

I've created a plunkr: http://plnkr.co/edit/JOeqcFqagiI5z4YKNU65?p=preview (you can run it on your phone: http://run.plnkr.co/MOVkJip5LSMklY4O/)

Preferred answer is in Javascript, but I can port.

markmarijnissen
  • 5,569
  • 2
  • 28
  • 34

1 Answers1

0

to get you started,

euler angle define a versor (orientation) that goes down, towards center of earth, such as:

   x = cos(alpha)cos(beta);
   y = cos(alpha)sin(beta);
   z = sin(alpha);
   Vector3 versor = new Vector3(x, y, z);

(probably you'll have to fix this ±alpha±Math.PI/2, depending on how the euler is expressed, where is 0° and so on) Using this vector, gravity will generate a force of:

Vector3 force = 9.81 * versor;

thus, if you have the accellerometer read (that is force) you can calculate:

double grav = Math.sqrt(Math.pow(acc.x/versor.x, 2) + Math.pow(acc.y/versor.y) + Math.pow(acc.z/versor.z));

or the force on the device that is not caused by gravity:

   Vector3 not_gravitational_force = acc - (9.81 * versor);
Exceptyon
  • 1,584
  • 16
  • 23