Search code examples
androidandroid-sensorsandroid-orientation

Android getOrientation() returns azimuth, positive or negative?


Assumption: the phone is held flat (parallel with the ground).

I am using getRotationMatrix() and getOrientation (float[] R, float[] values) to get the azimuth. Under this assumption, the azimuth is simply values[0].

The documentation says:

All three angles above are in radians and positive in the counter-clockwise direction.

Then I checked, when my phone's y axis points to the North, the azimuth is indeed 0.

However, here comes the problem: when my phone's y axis points to West, i.e. I rotated my phone counter-clockwise to make it point from North to West, the azimuth is negative!

Shouldn't the angle be positive when it is rotated counter-clockwise from North?

Where goes wrong?


Solution

  • No, if the positive direction of Z points to the sky then when y axis points to West then the angle is positive. But the coordinate used in getOrientation the positive direction of Z points down to the earth, thus now what seems counter-clockwise becomes clockwise, so West is negative.