If you read my answer at Convert magnetic field X, Y, Z values from device into global reference frame You still do not understand it.
A1. You multiply the Rotation matrix with the coordinates of the magnetic field vector in device coordinate system to get the coordinates of the magnetic field vector in the world coordinate system.
Let me emphasize: The above said Rotation matrix and not inverted rotation matrix.
The Rotation matrix obtained by calling getRotationMatrix
is the change of basis matrix from the device basis to the world basis. That is given any vector v with coordinates in device coordinate sytem, the coordinates in world coordinate system of the same vector v can be obtained by multiply the rotation matrix with the coordinates in device system coordinate.
The inverted rotation matrix is the change of basis matrix from the world basis to the device basis. Thus when you multitply this matrix with a coordinates, it is interpreted as multiply the matrix with the coordinates of a vector in world coordinate system to obtain the coordinates of the same vector in device coordinate system. Therefore if you multiply the inverted rotation matrix with the coordinates of the magnetic field vector as returned by the magnetic sensor. Then the coordinates is interpreted as the coordinates of a vector in the world coordinate system and thus do not represent the magnetic field vector and the resulting product is not the coordinates of the magnetic field vector in the world coordinates system. Actually it is the coordinates of a vector in device coordinate system.
A2. getOrientation
is meaningful only if the device is flat. For me it just a bunch of angle calculations. I look at what I try to do geometrically and then use the rotation matrix to calculate what I want. For example, to calculate the direction where the back camera pointed, I look at it as the direction of -z (the opposite of the vector orthogonal to the screen). Thus to find this direction, I projected -z to the world East-North plane and calculate the angle between this projection vector and the North axis. Now if you think this way then rotation of the device will not change the direction of -z, thus the projection vectors are the same as you rotate the device. If you use getOrientation
then you have to precall remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR)
for getOrientation
to give you the correct result.
A3. The getRotationMatrix
assumes that the geomagnetic parameter is the coordinates of a vector lying entirely in the North-Sky plane. Well any vector lying in this plane has to have x coordinate equal to 0. This is just basic linear algebra.
A4. The answer is no. To get the spatial position you have to be to express these vectors relative to a fixed coordinate system. with only coordinates of these vectors in device coordinate system, there is no way you can find a fixed basis that allow you to calculate the change of basis matrix from the device basis to this fixed basis. The 2 conditions stated in my link above need to be satisfied to calculate the change of basis.