title: numpy : Finding the tranformation matrix given 2 sets of 4 points in 3D euclidian coordinates
body: <p>I am trying to solve the transformation matrix M (in its numerical form). Source points are known (s1,s2,s3,s4) destination points are kwnown too (d1,d2,d3,d4). Points from a pyramid.
  The transformation is arbitrary and maps each point sn to its destination dn.</p>
  
  <p>Obviously s1 to s4 and d1 to d4 are known and use numerical values, just presenting them like this for clarity</p>
  
  <pre><code>s1  = np.matrix([[s1x],[s1y],[s1z],[0]])
  s2 = np.matrix([[s2x],[s2y],[s2z],[0]])
  s3 = np.matrix([[s3x],[s3y],[s3z],[0]])
  s4 = np.matrix([[s4x],[s4y],[s4z],[0]])
  
  d1  = np.matrix([[d1x],[d1y],[d1z],[0]])
  d2 = np.matrix([[d2x],[d2y],[d2z],[0]])
  d3 = np.matrix([[d3x],[d3y],[d3z],[0]])
  d4 = np.matrix([[d4x],[d4y],[d4z],[0]])
  </code></pre>
  
  <p>for each point, dn =  M x sn
  with :</p>
  
  <pre><code>M = np.matrix([4,4])
  </code></pre>
  
  <p>the general formula seems to be here: <a href="https://en.wikipedia.org/wiki/Transformation_matrix#Finding_the_matrix_of_a_transformation" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Transformation_matrix#Finding_the_matrix_of_a_transformation</a></p>
  
  <p>I am basically trying to put this in code form, if possible reducing the complexity in order to use numpy linalg solvers.</p>
  
  <p>I checked other threads, my question is really about the general case. (with the minimum number of 4 points needed)</p>