Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that your matrix is singular, meaning it's not invertible. Since you're trying to take the inverse of it, that's a problem. The thread that you linked to is a basic solution to your problem, but it's not really the best solution. Rather than just inverting the matrix, what you actually want to do is solve a least-squares minimization problem to find the optimal affine transform matrix for your possibly noisy data. Here's how you would do that:</p> <pre><code>import numpy as np primary = np.array([[40., 1160., 0.], [40., 40., 0.], [260., 40., 0.], [260., 1160., 0.]]) secondary = np.array([[610., 560., 0.], [610., -560., 0.], [390., -560., 0.], [390., 560., 0.]]) # Pad the data with ones, so that our transformation can do translations too n = primary.shape[0] pad = lambda x: np.hstack([x, np.ones((x.shape[0], 1))]) unpad = lambda x: x[:,:-1] X = pad(primary) Y = pad(secondary) # Solve the least squares problem X * A = Y # to find our transformation matrix A A, res, rank, s = np.linalg.lstsq(X, Y) transform = lambda x: unpad(np.dot(pad(x), A)) print "Target:" print secondary print "Result:" print transform(primary) print "Max error:", np.abs(secondary - transform(primary)).max() </code></pre> <p>The reason that your original matrix was singular is that your third coordinate is always zero, so there's no way to tell what the transform on that coordinate should be (zero times anything gives zero, so any value would work).</p> <p>Printing the value of <code>A</code> tells you the transformation that least-squares has found:</p> <pre><code>A[np.abs(A) &lt; 1e-10] = 0 # set really small values to zero print A </code></pre> <p>results in </p> <pre><code>[[ -1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 0. 0.] [ 650. -600. 0. 1.]] </code></pre> <p>which is equivalent to <code>x2 = -x1 + 650, y2 = y1 - 600, z2 = 0</code> where <code>x1, y1, z1</code> are the coordinates in your original system and <code>x2, y2, z2</code> are the coordinates in your new system. As you can see, least-squares just set all the terms related to the third dimension to zero, since your system is really two-dimensional.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload