How should I calculate azimuth, pitch, orientation when my Android device isn't flat?

前端 未结 2 1744
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 02:54

I\'m using the Android gravity and magnetic field sensors to calculate orientation via SensorManager.getRotationMatrix and SensorManager.getOrientation. This gives me the a

2条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 03:05

    I think the best way of defining your orientation angles when the device isn't flat is to use a more appropriate angular co-ordinate system that the standard Euler angles that you get from SensorManager.getOrientation(...). I suggest the one that I describe here on math.stackexchange.com. I've also put some code that does implements it in an answer here. Apart from a good definition of azimuth, it also has a definition of the pitch angle which is exactly the angle given by Math.acos(rotationMatrix[8]) that is mentioned in another answer here.

    You can get full details from the two links that I've given in the first paragraph. However, in summary, your rotation matrix R from SensorManager.getRotationMatrix(...) is

    equation with definition of R matrix

    where (Ex, Ey, Ez), (Nx, Ny, Nz) and (Gx, Gy, Gz) are vectors pointing due East, North, and in the direction of Gravity. Then the azimuth angle that you want is given by

    equation defining the azimuth angle

提交回复
热议问题