In fact, you can set (only) the vertical position without measuring acceleration over time. This is achieved by measuring the angle between the direction to the center of the earth and the direction to the magnetic north pole.
This changes (significantly) when the height (height) of the phone changes. You can use accelerometer and magnetometer to get two float arrays [3], treat them as vectors, make them unit vectors, and then the angle between any two unit vectors - arccos (AxM).
Pay attention to the point product, i.e. math.acos(A[0]*B[0]+A[1]*B[1]+A[2]*B[2]) Any change in this angle corresponds to a change in height. Also note that this will need to be calibrated to real units, and the ratio of the change in angle to height will differ at different longitudes; But this is a method of obtaining the absolute value of the height; although, of course, the angle also becomes distorted during acceleration or in the presence of nearby magnets :)
RoninSeito Jan 21 '14 at 2:20 2014-01-21 02:20
source share