Given points X,Y,Z on plane A that are then affined transformed using matrix M to a plane B with points X,Y,Z now translated to points x,y,z on plane B how do I calculate matrix M if I know all the values X,Y,Z and x,y,z ? So that I can enter a new point on Plane A (point d) and get its corresponding point on Plane B (point w).
My question is based on the formula in the following article http://www.alessiovaleri.it/using-transform-matrix-for-pcb-drilling-part-1/
which uses the following formula:
T1 = $ \begin{pmatrix} x1 & x2 & x3\\ y1 & y2 & y3\\ 1 & 1 & 1\\ \end{pmatrix} $
T2 = $ \begin{pmatrix} X1 & X2 & X3\\ Y1 & Y2 & Y3\\ \end{pmatrix} $
$M = T2 * T1^{-1}$
note all values xyz and XYZ are known for the above formula. Then to calculate point w would be:
$ \begin{pmatrix} x\\ y\\ 1\\ \end{pmatrix} = M * \begin{pmatrix} x1\\ y1\\ 1\\ \end{pmatrix} $
Is the formula correct would it be possible to provide proof ?
My proof of the formula fails with my python implementation. I get the correct Y value but not the correct X value
import numpy as np
#recorded points
rp1 = np.array([3, 0, 1])
rp2 = np.array([4, 0, 1])
rp3 = np.array([4, 2, 1])
#gcode points
gp1 = np.array([1, 0])
gp2 = np.array([2, 0])
gp3 = np.array([2, 2])
#test point gp4
gp4 = np.array([2, 1, 1])
#expected point
ex = np.array([4, 1])
T1 = np.array([rp1,
rp2,
rp3])
T2 = np.array([gp1,
gp2,
gp3])
T1 = T1.transpose()
T2 = T2.transpose()
print("Recorded Points T1:")
print(T1)
print("GCode Points T2:")
print(T2)
T1_inv = np.linalg.inv(T1)
M = T2.dot(T1_inv)
print("Inverse T1:")
print(T1)
print("Transform Matrix M:")
print(M)
print("Gcode point:")
print(gp4)
print("Expected transform:")
print(ex)
print("Actual transform:")
print(M.dot(gp4))
Result: Expected transform: [4 1] Actual transform: [-4.4408921e-16 1.0000000e+00]
Is my implementation incorrect, the formula incorrect or both?
All help appreciated
You’ve either got the source and destination points swapped, or you’ve gotten the sign of the translation wrong when you computed the image of the test point some other way. Assuming that source and destination are correct, this transformation is a translation to the left by 2 units, so the image of $(2,1)$ should be $(0,1)$, not $(4,1)$. The first coordinate of your actual result is close to zero, so the code to compute the transformation matrix is likely correct, up to the limits of precision.