Find the Rotation and Skew of a Matrix transformation

后端 未结 2 1785
温柔的废话
温柔的废话 2020-12-14 19:29

I have the the following Transform Matrix in CSS

// rotate the element 60deg
element.style.transform = \"matrix(0.5,0.866025,-0.866025,0.5,0,0)\"
         


        
2条回答
  •  Happy的楠姐
    2020-12-14 20:09

    Found the definition of your matrices here. We have the transformation matrix T

        / a b tx \
    T = | c d ty |
        \ 0 0 1  /
    

    For the following expression

    element.style.transform = "matrix(a,b,c,d,tx,ty)"
    

    In order to retrive the parameters used to build up this matrix we need to first find a decomposition of the matrix T. Assuming the skew is applied after the rotation we can find the QR-decomposition:

    QR = T

    The rotation will be found inside the Q matrix in the form of a pure rotation matrix. You can then use trigonometry to find out the single rotation angle, for example like so

    rotation = atan2(Q21, Q11)
    

    The skew and translation will be found in the R matrix.

        / sx   k  tx \
    R = |  0  sy  ty |
        \  0   0   1 /
    

    Where sx and sy is the scale and k represents the shear. I dont know how this shear relates to the css-skew.

    I don't know if the QR decomposition is availble in javascript, but it should be easy enough to implement using the Numerical Recipes as reference.

    Not a complete answer to get the parameters to create a new matrix object, but should set you off in the right direction!

提交回复
热议问题