Android: understanding the function remapCoordinateSystem

9k views Asked by At

I have been trying to understand these 2 lines of code

SensorManager.getRotationMatrix(RTmp, I, grav, mag); 
SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_X,SensorManager.AXIS_MINUS_Z, Rot);

I read the documentation of remapCoordinateSystem(), however I am lost.

Can anyone explain to me what exactly getRotationMatrix and remapCoordinateSystem do? Specially the SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z?

3

There are 3 answers

0
Johnnycube On

Asking such a question totally out of context is generally hard to answer. Also you should get familiar with formatting (e.g: 4 spaces indicates code):

SensorManager.getRotationMatrix(RTmp, I, grav, mag);
SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_X,SensorManager.AXIS_MINUS_Z, Rot);

However:

I would say that you are on the right track using the documentation. As you see getRotationMatrix pulls the current rotation matrix needed to transform the "world coordinate system" to the current device coordinate system. Additionally remapcoordinateSystem transforms the given coordinate System accordingly to the given rotation Matrix. But as stated above - out of context it is hard to tell you WHY somebody is doing this.

0
Noname On

I believe getRotationMatrix() returns a rotation matrix that converts device coordinate to world coordinate, as mentioned in android documentation, not "world" to "device".

Computes the inclination matrix I as well as the rotation matrix R transforming a vector from the device coordinate system to the world's coordinate system which is defined as a direct orthonormal basis, where

0
user1659006 On

I think the function of getRotationMatrix() was clearly explained by @Noname. I am trying to answer your second and third questions considering remapCoordinateSystem() and SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z.

What remapCoordinateSystem() does is actually changing the CoordinateSystem, setting the new X, Y, Z-AXIS where SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z are the coordinate system of your phone. From your code, I believe you are doing augmented reality in portrait orientation. That's why you set Y-axis to SensorManager.AXIS_MINUS_Z FYI. If you want to do the same thing in landscape orientation, you will set the coordinate system as follow:

SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, Rot);

I hope this helps.