Convert 3D matrix to readable format

Since my knowledge of matrices is close to nil, I was looking for a helper method that could do the conversion from a matrix array to a readable format.

With a readable format, I mean:

{ translate : { x : 0, y : 0, z : 0 }, rotation : { x : 0, y : 90, z : 0 }, skew : { x : 0, y : 0 }, scale : { x : 0, y : 0, z : 0 } } 

In matrix format, I mean: matrix3d(0.00000000000000006123233995736766, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0.00000000000000006123233995736766, 0, 0, 0, 0, 1) .

I am browsing Google for such a method but cannot find it.

Is there such a method or how can I decrypt / calculate each type of transformation on each available axis?

Update: My friend came across http://web.iitd.ac.in/~hegde/cad/lecture/L6_3dtrans.pdf , will study this to try to get at least something.

+4
source share
1 answer

It is not easy to decompose the matrix back into the original transformations. I managed to expand the matrix scale*rotate*translate .

 function extract(m) { // supports only scale*rotate*translate matrix var radians = Math.PI / 180 var sX = Math.sqrt(m[0]*m[0] + m[1]*m[1] + m[2]*m[2]), sY = Math.sqrt(m[4]*m[4] + m[5]*m[5] + m[6]*m[6]), sZ = Math.sqrt(m[8]*m[8] + m[9]*m[9] + m[10]*m[10]) var rX = Math.atan2(-m[9]/sZ, m[10]/sZ) / radians, rY = Math.asin(m[8]/sZ) / radians, rZ = Math.atan2(-m[4]/sY, m[0]/sX) / radians if (m[4] === 1 || m[4] === -1) { rX = 0 rY = m[4] * -Math.PI/2 rZ = m[4] * Math.atan2(m[6]/sY, m[5]/sY) / radians } var tX = m[12]/sX, tY = m[13]/sX, tZ = m[14]/sX return { translate: [tX, tY, tZ], rotate: [rX, rY, rZ], scale: [sX, sY, sZ] } } 

But it will not work for any other order of transformations.

+1
source

All Articles