Question

I am working on a pedometer on Android. To improve it, I would love to distillate the vertical force from all the other forces.

Documentation suggests that the orientation sensor should not be used anymore, due to inaccuraccy, so I was looking to something else.

My idea was: Use the 'TYPE_GRAVITY' sensor to determine what real vertical axis is (from core of earth to sky) and then use that information to rotate the TYPE_LINEAR_ACCELERATION data and then only use the wanted axis.

I was wondering, is this possible? Or is it impossible to calculate the rotation needed from a single [x,y,z] gravity vector?

Was it helpful?

Solution

I'll try to approach this from a physics standpoint rather than an Android/programming standpoint:

Let's say the TYPE_GRAVITY sensor returns a vector G = [xG, yG, zG].

The TYPE_LINEAR_ACCELERATION sensor returns another vector A = [xA, yA, zA].

What you're looking for is the magnitude of the projection of A onto a unit vector in the direction of G. In other words, how much of A is in the direction of G?

First we need to get the unit vector in the direction of G, which we'll call Gunit (see what I did there?). To get this, we divide each component of G by its magnitude ||G||, where ||G|| is the square root of the sum of the squares of each component (the distance formula). Thus,

Gunit = [xG / ||G||, yG / ||G||, zG / ||G||]

The magnitude of the component of A in the direction of G is then given by computing the dot product:

A · Gunit = (xA * (xG / ||G||)) + (yA * (yG / ||G||)) + (zA * (zG / ||G||)).

The result is a scalar (not a vector), and that's the quantity you're looking for.

Here's a good wikipedia article for reference: http://en.wikipedia.org/wiki/Vector_projection

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top