Search code examples
matlabtransformationmatrix-multiplicationaffinetransform

Get 2d Affine transformation from 2 pair of points Matlab


I have matrix with 5 points in homogeneous coordinates x1(x1; y1; z1).. x4(x4; y4; z4). I know that after applying Affine transformation to this matrix x1 moved to x1_prime, x2 - to x2_prime. How can I find the transformation matrix?

I tried

X = [x1 x2];
X_prime = [x1_prime x2_prime];
T = X_prime/X;

But this does not work. After I apply T on my 4 points I get 1 segment.

enter image description here

I tried fitgeotrans() in Matlab, but I suppose I have used it incorrect. Could you please help me to find Affine transformation matrix in Matlab?

Thanks


Solution

  • With 2 points it is impossible to find Affine transformation matrix

     [a b c;
      d e f; 
      g h i].
    

    We need 3 points for it. Only then for each line of matrix we will have 3 unknowns and 3 equations. With 2 points we can find

    [a b;
     d e]
    

    part of matrix, then add 0 0 1's and we will get Affine transformation

       [a b 0;
        d e 0;
        0 0 1]