Question

I want to find the Azimuth angle of device when It is not FLAT to the ground.

Here is an already existing Answer but not complete for me:

Here is the accepted answer on this question, which is almost same. Inconsistent orientation sensor values on Android for azimuth/yaw and roll

Problem:

But in this question, accepted answer gives azimuth value in the range -89 to 89. I want to calculate Azimuth angle value in range 0-359 degree, when moving from Magnetic North. How can I calculate that in Android Sensors?

Was it helpful?

Solution 2

Found its answer:

Calculate azimuth angle like this:

mAzimuthAngleNotFlat = (int) Math.toDegrees(Math
                    .atan2((rotationMatrix[1] - rotationMatrix[3]), (rotationMatrix[0] + rotationMatrix[4])));

To convert it to 0 to 359 simply apply this:

    if (mAzimuthAngleNotFlat < 0) {
        mAzimuthAngleNotFlat += 360;
    }

Then you are done. And this angle will be accurate when device is not flat. For more, you can see discussion on accepted answer.

Inconsistent orientation sensor values on Android for azimuth/yaw and roll

OTHER TIPS

When the device is not flat and if you want your compass direction to be the negative of the direction of the device z-axis (i.e the direction you are looking at) then the azimuth can be calculate by first call

remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);

Then call

getOrientation (float[] R, float[] values)

passing in outR for the parameter R.

This amount to project the z-axis into the World xy plane and then calculate the angle between this projection and the World y-axis which is magnetic north.

The z-axis point in the same direction when the device is rotated around this axis, thus the azimuth should not change. Of course it will vary a little due to acceleration.

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