Search code examples
python-3.xnumpytransformationaffinetransformmatrix-decomposition

How to decompose affine matrix?


I have a series of points in two 3D systems. With them, I use np.linalg.lstsq to calculate the affine transformation matrix (4x4) between both. However, due to my project, I have to "disable" the shear in the transform. Is there a way to decompose the matrix into the base transformations? I have found out how to do so for Translation and Scaling but I don't know how to separate Rotation and Shear. If not, is there a way to calculate a transformation matrix from the points that doesn't include shear? I can only use numpy or tensorflow to solve this problem btw.


Solution

  • I'm not sure I understand what you're asking.

    Anyway If you have two sets of 3D points P and Q, you can use Kabsch algorithm to find out a rotation matrix R and a translation vector T such that the sum of square distances between (RP+T) and Q is minimized. You can of course combine R and T into a 4x4 matrix (of rotation and translation only. without shear or scale).