简体   繁体   中英

invert and multiply rotation matrix android?how to

I want to make the following calculus using the rotation matrix extracted from the method getRotationMatrix() :

SensorManager.getRotationMatrix(mRi, mI, mGData1, mMData2);

SensorManager.getRotationMatrix(mRi, mI, mGData, mMData);

//invert(mRi) and multiply it by mR, mRi and mR are float[] with length 16, is this the right way? I'm not getting any result. Rmult returns 0.         

Matrix.invertM(Rinv,0,mRi,0);
Matrix.multiplyMM(Rmult, 0, Rinv, 0, mR, 0);

How can I do it?

The inverse of a rotation matrix (with no translation/scale/shear) is the transpose of the matrix, that is using the rows as the columns. Note that this is a special case, the transpose for any matrix is not the inverse, it just works for rotation matrices.

That means that the elements with indices 0, 1, 2, 3 in the transposed matrix would be the values with indices 0, 4, 8, 12, the values with indices 4, 5, 6, 7 would be the values with indices 1, 5, 9, 13, and so on.

Though, if you plan on post-multiplying with the transpose, it may be easier not to do the transpose at all in the first place, because multiplying with the transpose of a matrix directly more closely matches the memory layout so one can do parallel multiplies (if you ever want to go so far as to use SIMD).

It seeems you are using the opengl Possibly because the matrices you use are the android.opengl.Matrix functions, right? Could it be that your matrices do not have the required 4x4 (that is, float[16]) format?

I am by no means and expert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM